Class LspServer
Denotes the implementation of an LSP server
public class LspServer : ILspServer
- Inheritance
-
LspServer
- Implements
- Derived
- Inherited Members
Constructors
LspServer(params Grammar[])
Creates a new instance
public LspServer(params Grammar[] grammars)
Parameters
grammarsGrammar[]A collection of grammars
LspServer(IEnumerable<Grammar>, bool)
Creates a new instance
public LspServer(IEnumerable<Grammar> grammars, bool asyncChanges = false)
Parameters
grammarsIEnumerable<Grammar>A collection of grammars
asyncChangesbooltrue, if changes should be processed asynchronously, otherwise false
Properties
Documents
Gets the raw dictionary of open documents
protected IDictionary<string, Parser> Documents { get; }
Property Value
Grammars
Gets the raw dictionary of grammars
protected IDictionary<string, Grammar> Grammars { get; }
Property Value
OpenDocuments
Gets a collection of currently opened documents
public ICollection<Parser> OpenDocuments { get; }
Property Value
Methods
ApplyWorkspaceEditAsync(WorkspaceEdit, string)
Sends a workspace/applyEdit to the client.
public Task<ApplyWorkspaceEditResponse> ApplyWorkspaceEditAsync(WorkspaceEdit edit, string label)
Parameters
editWorkspaceEditThe
WorkspaceEditto apply.labelstringA descriptive label for the edit operation.
Returns
- Task<ApplyWorkspaceEditResponse>
A
Taskrepresenting the asynchronous operation, containing theApplyWorkspaceEditResponse.
CloseDocument(Parser)
Gets called when a document is closed
protected virtual void CloseDocument(Parser parser)
Parameters
parserParserthe closed document
CodeAction(JToken)
Handles the textDocument/codeAction request from the client.
public CodeAction[] CodeAction(JToken arg)
Parameters
argJTokenThe JSON token containing the parameters of the request. (CodeActionParams)
Returns
- CodeAction[]
CodeLens(JToken)
Handles the textDocument/codeLens request from the client.
public CodeLens[] CodeLens(JToken arg)
Parameters
argJTokenThe JSON token containing the parameters of the request. (CodeLensParams)
Returns
- CodeLens[]
A Array of CodeLens(JToken) objects containing the available CodeLenses of the document.
CodeLensResolve(JToken)
Handles the codeLense/resolve request from the client.
public CodeLens CodeLensResolve(JToken arg)
Parameters
argJTokenThe JSON token containing the parameters of the request. (CodeLens)
Returns
- CodeLens
A CodeLens(JToken) object containing the executed CodeLens
DidChange(JToken)
Gets called when the client signals a change
public void DidChange(JToken arg)
Parameters
argJTokenthe parameters of the request
DidClose(JToken)
Gets called when the client closed a document
public void DidClose(JToken arg)
Parameters
argJTokenthe parameters of the request
DidOpen(JToken)
Gets called when the client opened a document
public void DidOpen(JToken arg)
Parameters
argJTokenthe parameters of the request
DidSave(TextDocumentIdentifier, string)
Gets called when the client saved a document
public void DidSave(TextDocumentIdentifier textDocument, string text)
Parameters
textDocumentTextDocumentIdentifierthe document to save
textstringthe actual text
ExecuteCommand(JToken)
Handles the workspace/ececuteCommand request from the client. This is used to execute an action on the
Server.
public void ExecuteCommand(JToken arg)
Parameters
argJTokenThe JSON token containing the parameters of the request. (ExceuteCommandParams)
Exit()
Gets called when the client exits
public void Exit()
Formatting(TextDocumentIdentifier, FormattingOptions)
Handles the textDocument/formatting request from the client.
public TextEdit[] Formatting(TextDocumentIdentifier textDocument, FormattingOptions options)
Parameters
textDocumentTextDocumentIdentifierThe identifier of the text document to be formatted.
optionsFormattingOptionsThe formatting options provided by the client, such as indentation and spacing settings.
Returns
- TextEdit[]
An array of TextEdit objects representing the formatting changes.
FormattingRange(TextDocumentIdentifier, Range, FormattingOptions)
Handles the textDocument/rangeFormatting request from the client.
public TextEdit[] FormattingRange(TextDocumentIdentifier textDocument, Range range, FormattingOptions options)
Parameters
textDocumentTextDocumentIdentifierThe identifier of the text document to be formatted.
rangeRangeThe range within the document that should be formatted.
optionsFormattingOptionsThe formatting options provided by the client, such as indentation and spacing settings.
Returns
- TextEdit[]
An array of TextEdit objects representing the formatting changes within the specified range.
HandleCompletion(JToken)
Suggests completions
public CompletionList HandleCompletion(JToken arg)
Parameters
argJToken
Returns
- CompletionList
A completion list
HandleExtensionCommand(string, object[])
Allows derived classes to handle an extension command
protected virtual bool HandleExtensionCommand(string commandIdentifier, object[] args)
Parameters
Returns
- bool
true, if the command was handled, otherwise false
Hover(JToken)
Handles the textDocument/hover request from the client.
public Hover Hover(JToken arg)
Parameters
argJTokenThe JSON token containing the parameters of the request. (TextDocumentHover)
Returns
- Hover
Initialize(int?, _InitializeParams_ClientInfo, string, string, Uri, ClientCapabilities, TraceValue, WorkspaceFolder[], object)
Initializes the server
public InitializeResult Initialize(int? processId, _InitializeParams_ClientInfo clientInfo, string locale, string rootPath, Uri rootUri, ClientCapabilities capabilities, TraceValue trace, WorkspaceFolder[] workspaceFolders, object InitializationOptions = null)
Parameters
processIdint?clientInfo_InitializeParams_ClientInfolocalestringthe language
rootPathstringrootUriUricapabilitiesClientCapabilitiescapabilities of the client
traceTraceValueworkspaceFoldersWorkspaceFolder[]workspace folders
InitializationOptionsobjectoptions for the initialization
Returns
- InitializeResult
Initialized()
Initializes the server
public void Initialized()
OnDocumentUpdate(Parser, IEnumerable<TextEdit>, string)
Gets called when a document should be updated
protected virtual void OnDocumentUpdate(Parser document, IEnumerable<TextEdit> edits, string uri)
Parameters
documentParserthe parsed document
editsIEnumerable<TextEdit>the edits that should be performed
uristringthe URI of the document
OpenNewDocument(Parser)
Gets called when a new document is opened
protected virtual void OpenNewDocument(Parser parser)
Parameters
parserParserthe opened document
PostProcessCompletions(Parser, IEnumerable<CompletionItem>)
Performs a post-processing on the given completion collection
protected virtual IEnumerable<CompletionItem> PostProcessCompletions(Parser document, IEnumerable<CompletionItem> completions)
Parameters
documentParserthe document for which the completion list is requested
completionsIEnumerable<CompletionItem>the current list of completions
Returns
- IEnumerable<CompletionItem>
a potentially modified list of completions
ProvideInlayHints(JToken)
Provides Inlay hints for the document
public InlayHint[] ProvideInlayHints(JToken arg)
Parameters
argJTokenThe parameters of the request
Returns
- InlayHint[]
A list of inlay hints
QueryDefinition(JToken)
Handles the textDocument/definition request from the client. This is used to retrieve the location
of the definition of a symbol in a document.
public LocationLink[] QueryDefinition(JToken arg)
Parameters
argJTokenThe JSON token containing the parameters of the request. (TextDocumentPositionParams)
Returns
- LocationLink[]
A list of LspTypes.LocationLink objects containing the documents and positions of the definitions of a symbol.
QueryDocumentHighlights(JToken)
Handles the textDocument/documentHighlight request from the client. This is used to retrieve the locations and kinds
of all highlights for a literal at a given position in the document.
public DocumentHighlight[] QueryDocumentHighlights(JToken arg)
Parameters
argJTokenThe JSON token containing the parameters of the request. (DocumentHighlightParams)
Returns
- DocumentHighlight[]
An array of LspTypes.DocumentHighlight objects containing the range and kind of all matching highlights in the document.
QueryDocumentSymbols(JToken)
Denotes an interface for an LSP server
public DocumentSymbol[] QueryDocumentSymbols(JToken arg)
Parameters
argJToken
Returns
- DocumentSymbol[]
QueryFoldingRanges(JToken)
Handles the textDocument/foldingRange/full request from the client. This is used to retrieve all folding ranges for a document.
public FoldingRange[] QueryFoldingRanges(JToken arg)
Parameters
argJTokenThe JSON token containing the parameters of the request. (FoldingRangeParams)
Returns
- FoldingRange[]
An array of FoldingRange objects, each containing details on a folding range in the document.
QueryReferences(JToken)
Handles the textDocument/references request from the client. This is used to retrieve the locations
of all references to a symbol in a document.
public Location[] QueryReferences(JToken arg)
Parameters
argJTokenThe JSON token containing the parameters of the request. (ReferenceParams)
Returns
- Location[]
An array of LspTypes.Location objects containing the documents and locations of the references to a symbol.
QueryRenameWorkspaceEdit(JToken)
Handles the textDocument/rename request from the client. This is used to determine the locations of a symbol
in a workspace to perform a workspace-wide rename.
public WorkspaceEdit QueryRenameWorkspaceEdit(JToken arg)
Parameters
argJTokenThe JSON token containing the parameters of the request. (RenameParams)
Returns
- WorkspaceEdit
A LspTypes.WorkspaceEdit object containing the changes to be performed by the client.
QuerySelectionRanges(JToken)
Handles the textDocument/selectionRange request from the client. This is used to retrieve selection ranges
at an array of given positions in a document.
public SelectionRange[] QuerySelectionRanges(JToken arg)
Parameters
argJTokenThe JSON token containing the parameters of the request. (SelectionRangeParams)
Returns
- SelectionRange[]
An array of SelectionRange objects, each containing details on a selection range in the document corresponding to the received positions.
QuerySemanticTokens(JToken)
Handles the textDocument/semanticTokens/full request from the client. This is used to retrieve all semantic
tokens for a document.
public SemanticTokens QuerySemanticTokens(JToken arg)
Parameters
argJTokenThe JSON token containing the parameters of the request. (SemanticTokensParams)
Returns
- SemanticTokens
A LspTypes.SemanticTokens object containing the full set of semantic tokens for the document.
QuerySemanticTokensDelta(JToken)
Handles the textDocument/semanticTokens/full/delta request from the client. This is used to retrieve only
the changes (delta) in semantic tokens for a document.
public SemanticTokensDelta QuerySemanticTokensDelta(JToken arg)
Parameters
argJTokenThe JSON token containing the parameters of the request. (SemanticTokensDeltaParams)
Returns
- SemanticTokensDelta
A LspTypes.SemanticTokensDelta object containing only the delta of semantic tokens for the document.
QuerySemanticTokensRange(JToken)
Handles the textDocument/semanticTokens/full/delta request from the client. This is used to retrieve only
the changes (delta) in semantic tokens for a document.
public SemanticTokens QuerySemanticTokensRange(JToken arg)
Parameters
argJTokenThe JSON token containing the parameters of the request. (SemanticTokensDeltaParams)
Returns
- SemanticTokens
A LspTypes.SemanticTokensDelta object containing only the delta of semantic tokens for the document.
SendLogMessageAsync(MessageType, string, bool)
Sends a log message to the client.
protected Task SendLogMessageAsync(MessageType type, string message, bool always = false)
Parameters
typeMessageTypeThe type of the message (Info, Warning, Error).
messagestringThe message content.
alwaysboolWhether to always log this message even when not debugging. Warnings and errors are always logged regardless.
Returns
SetRpc(JsonRpc)
Sets the JSON-RPC instance used by the server for communication with the client.
public void SetRpc(JsonRpc rpc)
Parameters
SetTrace(JToken)
Handles the $/setTrace request from the client. This is used to set the trace setting of the server.
public void SetTrace(JToken arg)
Parameters
argJTokenThe JSON token containing the parameters of the request. (SetTraceParams)
ShowDocument(string, Range, bool, bool)
Sends the window/showDocument request to the client.
protected Task ShowDocument(string uri, Range selection = null, bool external = false, bool takeFocus = false)
Parameters
uristringThe URI of the document to show.
selectionRangeThe optional selection range in the document.
externalboolIf true, requests to open the document externally.
takeFocusboolIf true, requests the client to take focus.
Returns
ShowMessageNotify(string, MessageType)
Sends a message notification window/showMessage to the client without expecting a response.
protected Task ShowMessageNotify(string message, MessageType messageType)
Parameters
messagestringThe message to display.
messageTypeMessageTypeThe type of message (Info, Warning, Error, Log).
Returns
ShowMessageRequestAsync(string, MessageType, IEnumerable<string>)
Sends a message request window/showMessageRequest to the client and awaits a response.
protected Task<MessageActionItem> ShowMessageRequestAsync(string message, MessageType messageType, IEnumerable<string> titles)
Parameters
messagestringThe message to display.
messageTypeMessageTypeThe type of message (Info, Warning, Error, Log).
titlesIEnumerable<string>A collection of action button titles the user can choose from.
Returns
- Task<MessageActionItem>
The selected LspTypes.MessageActionItem if the client supports the request; otherwise, null.
ShowReferencesNotifyAsync(ParsePosition)
Sends a custom/showReferences notification to the client without expecting a response
protected Task ShowReferencesNotifyAsync(ParsePosition position)
Parameters
positionParsePositionThe position of the symbol in the document to show references for
Returns
Shutdown()
Shuts down the server
public void Shutdown()
TryGetOpenDocument(string, out Parser)
Tries to fetch the given open document
public bool TryGetOpenDocument(string documentUri, out Parser document)
Parameters
documentUristringthe URI of the document
documentParserthe document or null, if it was not found
Returns
- bool
true, if the document was found, otherwise false