vuejs / vetur

Vue tooling for VS Code.
https://vuejs.github.io/vetur/
MIT License
5.74k stars 592 forks source link

vls doesn't work with monaco-languageclient. #3401

Open FoxDaxian opened 2 years ago

FoxDaxian commented 2 years ago

Info

Problem

I changed json to vue of node demo of monaco-languageclient as below:

import * as vls from "vls";
export function start(reader: MessageReader, writer: MessageWriter) {
    const connection = createConnection(reader, writer);
    new vls.VLS(connection);
    _vls.listen();
}

But it is not work after those change. image

So how to connect monaco-editor with vls?

Any answer would be greatly appreciated. thank you!

Reproducible Case

As above.

FoxDaxian commented 2 years ago

Whether to support worker like this:

import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
import htmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker';

import vueWorker from 'vls/vue.worker';  <--- here

self.MonacoEnvironment = {
    getWorker(_: any, label: string) {
        console.log(label, '==label');
        if (label === 'json') {
            return new jsonWorker();
        }
        if (label === 'vue') {     <---- and here
           return new vueWorker();
        }
        if (label === 'html' || label === 'handlebars' || label === 'razor') {
            return new htmlWorker();
        }
        return new editorWorker();
    }
};
phil294 commented 2 years ago

what errors are you seeing? Vetur has several ways to log and debug attach to lsp server. If the initialization process fails, either monaco or vetur will tell you about it afaik.

FoxDaxian commented 2 years ago

@phil294 thank you for reply

There is no error when run server. looks like as below: image

And code like this:

connection.onInitialize(async (params) => {
        await _vls.init(params);

        console.log("Vetur initialized =====");

        return {
            capabilities: _vls.capabilities,
        };
});
FoxDaxian commented 2 years ago

@phil294 Sorry to disturb~ this is the lastest process: discussions

FoxDaxian commented 2 years ago

I found textDocument/didOpen event get wrong params like:

{
  jsonrpc: '2.0',
  method: 'textDocument/didOpen',
  params: {
    textDocument: {
      uri: 'inmemory://model/1', <----- I think this is incorrect uri
      languageId: 'vue',
      version: 1,
      text: ''
    }
  }
}

I'm not pass default value for monaco-editor, so it is no content by default. and the uri of textDocument looks like the source code stored in the memory?

how to resolve this problem? thanks~

FoxDaxian commented 2 years ago

here is the repo about thi question: repo

FoxDaxian commented 2 years ago

here is related issue

FoxDaxian commented 2 years ago

anybody? help~

@HerringtonDarkholme @yoyo930021 sorry to disturb~ 🙏🏻

redbullmarky commented 2 years ago

@FoxDaxian

i used https://github.com/wylieconlon/jsonrpc-ws-proxy and, with a couple of configuration bits inside of the client.ts, had it up and running (syntax, suggestions, etc). Only syntax highlighting to go.

the workspaceFolder inside of the clientOptions (in client.js), i set it to the folder where the server's files live.

This article was invaluable: https://medium.com/dscddu/language-server-protocol-adding-support-for-multiple-language-servers-to-monaco-editor-a3c35e42a98d

i can't pretend to know exactly how it's working as yet, because documentation on some of these things is very slim and right now it's just about getting it working - the end target is Volar, but that doesn't seem to integrate in the same way :-p

Good luck.

FoxDaxian commented 2 years ago

@redbullmarky thanks for reply very much. 😊 and i'll try this way what you mention. and wish me luck. 😭

yoyo930021 commented 1 year ago

The vetur can't work well in environments other than nodejs.

Vetur is based on typescript language service. The typescript language service can't work well for this.