code_forge_web 1.0.0
code_forge_web: ^1.0.0 copied to clipboard
The web version of the powerful [code_forge](https://github.com/heckmon/code_forge) package
This is the web version of the powerful code_forge package.
This package can load files from raw URLs and the LspSocketConfig() class can be used to enable LSP features, which makes the code_forge_web the ideal choice for browser based code editors.
Difference from code_forge #
Almost all features in the code_forge are same in this package except the file handling and the LSP initialization.
The CodeForgeWeb has a fileUrl parameter instead of the filePath parameter of the CodeForge, where the user can pass raw file URLs.
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late final CodeForgeWebController controller;
@override
void initState() {
super.initState();
controller = CodeForgeWebController(
lspConfig: LspSocketConfig(
workspacePath: "file:///workspace", // Virtual workspace name
languageId: "dart", // Language id
serverUrl: "ws://localhost:9000" // The LSP server url.
)
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: Scaffold(
body: SafeArea(
child: CodeForgeWeb(
// Working url of any file.
fileUrl: "https://raw.githubusercontent.com/heckmon/code_forge/main/lib/code_forge/controller.dart",
controller: controller,
textStyle: GoogleFonts.jetBrainsMono(fontSize: 20),
innerPadding: EdgeInsets.only(top: 10),
)
),
),
);
}
}
To host a LSP server, you can use the lsp-ws-proxy package.
Here is an example of running dart language server via websocket:
./lsp-ws-proxy --listen 0.0.0.0:9000 -- dart language-server --protocol=lsp
This will start and run the LSP server on the localhost:9000. You can pass the link ws://localhost:9000 to the LspSocketConfig() to enable LSP features like in the above example.