LspStdioConfig class

This class provides a configuration for Language Server Protocol (LSP) using standard input/output communication. Little bit complex compared to LspSocketConfig.

/// Documenation available here.

Example:

Create an async method to initialize the LSP configuration.

Future<LspConfig?> _initLsp() async {
   try {
     final config = await LspStdioConfig.start(
       executable: '/home/athul/.nvm/versions/node/v20.19.2/bin/pyright-langserver',
       args: ['--stdio']
       filePath: '/home/athul/Projects/lsp/example.py',
       workspacePath: '/home/athul/Projects/lsp',
       languageId: 'python',
     );

     return config;
   } catch (e) {
     debugPrint('LSP Initialization failed: $e');
     return null;
   }
 }

Then use a FutureBuilder to initialize the LSP configuration and pass it to the CodeCrafter widget:

 @override
 Widget build(BuildContext context) {
   return MaterialApp(
     home: Scaffold(
       body: SafeArea(
         child: FutureBuilder(
           future: _initLsp(), // Call the async method to get the LSP config
           builder: (context, snapshot) {
             if(snapshot.connectionState == ConnectionState.waiting) {
               return Center(child: CircularProgressIndicator());
             }
             return CodeCrafter(
               wrapLines: true,
               editorTheme: anOldHopeTheme,
               controller: controller,
               filePath: '/home/athul/Projects/lsp/example.py',
               textStyle: TextStyle(fontSize: 15, fontFamily: 'monospace'),
               lspConfig: snapshot.data, // Pass the LSP config here
             );
           }
         ),
       )
     ),
   );
 }
Inheritance

Properties

args → List<String>?
Optional arguments for the executable.
final
disableError → bool
Whether to disable errors from the LSP server.
finalinherited
disableWarning → bool
Whether to disable warnings from the LSP server.
finalinherited
environment → Map<String, String>?
Optional environement variables for the executable.
final
executable → String
location of the LSP executable, such as pyright-langserver, rust-analyzer, etc.
final
filePath → String
The file path of the document to be processed by the LSP.
finalinherited
hashCode → int
The hash code for this object.
no setterinherited
languageId → String
The language ID of the language.
finalinherited
responses → Stream<Map<String, dynamic>>
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
workspacePath → String
The workspace path of the document to be processed by the LSP.
finalinherited

Methods

closeDocument() → Future<void>
Updates the document in the LSP server if there is any change. /// This method is used internally by the CodeCrafter widget and calling it directly is not recommended.
inherited
dispose() → void
override
getCompletions(int line, int character) → Future<List<LspCompletion>>
This method is used to get completions at a specific position in the document.
inherited
getDefinition(int line, int character) → Future<String>
inherited
getHover(int line, int character) → Future<String>
This method is used to get details at a specific position in the document.
inherited
getReferences(int line, int character) → Future<List>
inherited
initialize() → Future<void>
This method is used to initialize the LSP server.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openDocument() → Future<void>
Opens the document in the LSP server.
inherited
toString() → String
A string representation of this object.
inherited
updateDocument(String content) → Future<void>
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

start({required String executable, required String filePath, required String workspacePath, required String languageId, List<String>? args, Map<String, String>? environment, bool disableWarning = false, bool disableError = false}) → Future<LspStdioConfig>