microsoft / language-server-protocol

Defines a common protocol for language servers.
https://microsoft.github.io/language-server-protocol/
Creative Commons Attribution 4.0 International
10.91k stars 763 forks source link

textDocumentSync usage - Question #1965

Closed deanmaster closed 5 days ago

deanmaster commented 5 days ago

Hello everyone,

i'm implementing a prototype of LSP. I stumb over a problem that the documents manager does not keep in sync with document which i'm editing on the Editor.

I read an article it said "the syncronization should be done out of the box by Documents manager" I checked the clientCapability it shows

"textDocument": {
      "synchronization": {
        "willSave": true,
        "willSaveWaitUntil": true,
        "didSave": true
      },

and server cabability it shows:

"capabilities": {
    "textDocumentSync": 2,
    "hoverProvider": true,
    "completionProvider": {
      "resolveProvider": false,
      "triggerCharacters": [
        "\"",
        ":"
      ]
    },

Could anyone let me know what's wrong ? in the Language Server code I do. It always show the original state on the disk but not what i'm editing. For sure I do not save the content to the disk yet because i'm doing autocompletion.

const document = documents.get(textDocumentPosition.textDocument.uri);

console.log("Found document [" + document.getText());

When I implement the onDidChange. The content sent here is really real time. This is what I need for my autocompletion. But I can't update the Documents manager with newest content from editor. I was hoping the manager does it on it owns.

connection.onDidChangeTextDocument(handler => {

Thanks a lot. A hint would be very helpful for me.

deanmaster commented 5 days ago

adding ProposedFeatures.all in to initialize of connection solved the problem.

const connection: Connection = createConnection(ProposedFeatures.all);