Description
The document open notification is sent from the client to the server to signal newly opened text documents. The document’s content is now managed by the client and the server must not try to read the document’s content using the document’s Uri. Open in this sense means it is managed by the client. It doesn’t necessarily mean that its content is presented in an editor. An open notification must not be sent more than once without a corresponding close notification send before. This means open and close notification must be balanced and the max open count for a particular textDocument is one. Note that a server’s ability to fulfill requests is independent of whether a text document is open or closed.
The server receives a TextDocumentItem
with the notification:
interface TextDocumentItem {
/**
* The text document's URI.
*/
uri: DocumentUri;
/**
* The text document's language identifier.
*/
languageId: string;
/**
* The version number of this document (it will increase after each
* change, including undo/redo).
*/
version: integer;
/**
* The content of the opened text document.
*/
text: string;
}
So this is where the server receives the text
of the document at a given version
. The languageId
should be vba
, to avoid clashing with "VB.NET" vb
. The uri
points to a path relative to the workspace root.
The string contains the complete file contents, including headings and attributes that are hidden in the VBIDE, so that's what we want to parse, and we'll want to quickly get a parse tree for it, cache it with the document uri
and version
as a key... and then sit on it for now - eventually the LSP server is going to send various notifications to the client, and we'll want to launch a semantic pass over all the parse trees and declarations, so having a parse tree associated to a specific version of a document URI is a very good starting point.
This supposes something is holding this state in some (thread-safe) dictionary: we'll need to inject a service that's responsible for just that.
- Have an abstraction that provides an API to map
TextDocumentItem
to a parse tree, and to retrieve a parse tree for a given document URI and version - Have an abstraction that provides a parse tree given the text content of a
TextDocumentItem
. - Implement a
DidOpenHandler
class- Inherit
OmniSharp.Extensions.LanguageServer.Protocol.Document.DidOpenTextDocumentHandlerBase
; constructor-inject state service - Implement the
Handle
override; access the document from therequest
parameter (DidOpenTextDocumentParams
). - Implement the
CreateRegistrationOptions
override (specifyDocumentSelector
filters)
- Inherit
Log successful execution of the handler at INFO
level; exceptions can be caught, but must be rethrown to return an error result at the JSON-RPC level.