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']
       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 CodeForge 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 CodeForge(
               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
exitCode Future<int>
no setter
hashCode int
The hash code for this object.
no setterinherited
isIntialized bool
getter/setter pairinherited
languageId String
The language ID of the language.
finalinherited
pid int
no setter
process Process
no setter
responses Stream<Map<String, dynamic>>
Stream of responses from the LSP server. Use this to listen for notifications like diagnostics.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
serverTokenModifiers List<String>?
The server's semantic token modifiers legend. Returns null if not yet initialized.
no setterinherited
serverTokenTypes List<String>?
The server's semantic token types legend. Returns null if not yet initialized.
no setterinherited
workspacePath String
The workspace path of the document to be processed by the LSP.
finalinherited

Methods

closeDocument(String filePath) Future<void>
Updates the document in the LSP server if there is any change. /// This method is used internally by the CodeForge widget and calling it directly is not recommended.
inherited
dispose() → void
override
executeCommand(String command, List? arguments) Future<void>
Execute a workspace command on the server Wrapper around the 'workspace/executeCommand' request.
inherited
exitServer() Future<void>
Exits the LSP server process.
inherited
formatDocument(String filePath) Future<List>
Formats the entire document according to server rules.
inherited
formatRange({required String filePath, required int startLine, required int startCharacter, required int endLine, required int endCharacter}) Future<List>
Formats a specific range in the document.
inherited
getCodeActions({required String filePath, required int startLine, required int startCharacter, required int endLine, required int endCharacter, List<Map<String, dynamic>> diagnostics = const []}) Future<List>
Retrieves available code actions at a given range.
inherited
getCompletions(String filePath, int line, int character) Future<List<LspCompletion>>
This method is used to get completions at a specific position in the document.
inherited
getDeclaration(String filePath, int line, int character) Future<Map<String, dynamic>>
Gets the declaration for a symbol at the specified position.
inherited
getDefinition(String filePath, int line, int character) Future<Map<String, dynamic>>
Gets the definition location for a symbol at the specified position.
inherited
Retrieves document links such as import paths and URLs.
inherited
getDocumentSymbols(String filePath) Future<List>
Retrieves all symbols defined in the current document.
inherited
getHover(String filePath, int line, int character) Future<String>
This method is used to get details at a specific position in the document.
inherited
getImplementation(String filePath, int line, int character) Future<Map<String, dynamic>>
Gets the implementation locations for a symbol at the specified position.
inherited
getIncomingCalls(Map<String, dynamic> item) Future<List>
Retrieves incoming calls for a call hierarchy item.
inherited
getOutgoingCalls(Map<String, dynamic> item) Future<List>
Retrieves outgoing calls for a call hierarchy item.
inherited
getReferences(String filePath, int line, int character) Future<List>
Gets all references to a symbol at the specified position.
inherited
getSemanticTokensFull(String filePath) Future<List<LspSemanticToken>>
Gets all semantic tokens for the document.
inherited
getSignatureHelp(String filePath, int line, int character) Future<Map<String, dynamic>>
Retrieves signature help at the given position.
inherited
getSubtypes(Map<String, dynamic> item) Future<List>
Retrieves subtypes (derived classes / implementations).
inherited
getSupertypes(Map<String, dynamic> item) Future<List>
Retrieves supertypes (base classes / interfaces).
inherited
getTypeDefinition(String filePath, int line, int character) Future<Map<String, dynamic>>
Jumps to the location where the data type of a symbol is defined.
inherited
getWorkspaceSymbols(String query) Future<List>
Searches for symbols across the entire workspace.
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(String filePath) Future<void>
Opens the document in the LSP server.
inherited
prepareCallHierarchy(String filePath, int line, int character) Future<Map<String, dynamic>?>
Prepares a call hierarchy item at the given position.
inherited
prepareRename(String filePath, int line, int character) Future<Map<String, dynamic>?>
Checks whether a symbol can be renamed at the given position.
inherited
prepareTypeHierarchy(String filePath, int line, int character) Future<Map<String, dynamic>?>
Prepares a type hierarchy item at the given position.
inherited
renameSymbol(String filePath, int line, int character, String newName) Future<Map<String, dynamic>>
Renames a symbol at the given position across the workspace.
inherited
resolveCompletionItem(Map<String, dynamic> item) Future<Map<String, dynamic>>
Resolves and retrieves additional details for the given LSP completion item.
inherited
saveDocument(String filePath, String content) Future<void>
Saves the document in the LSP server.
inherited
shutdown() Future<void>
Shuts down the LSP server gracefully.
inherited
toString() String
A string representation of this object.
inherited
updateDocument(String filePath, String content) Future<void>
Updates the document content in the LSP server.
inherited

Operators

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

Static Methods

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