Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with ProtocolToMonacoConverter #214

Closed
zkrami opened this issue Jun 8, 2020 · 14 comments
Closed

Issue with ProtocolToMonacoConverter #214

zkrami opened this issue Jun 8, 2020 · 14 comments
Labels

Comments

@zkrami
Copy link

zkrami commented Jun 8, 2020

I am implementing my own Language service provider trying to stick to the vscode-languageserver-protocol.

I am integrating my LSP with monaco editor.
However when I am using ProtocolToMonacoConverter.asCodeAction I am not receiving the expected json structure.

Here is the structure I am receiving:

 {
   "title":"Replace VLOOKUP",
   "edit":{
      "edits":[
         {
            "resource":{            
            },
            "edits":[
               {
                  "range":{
                     "startLineNumber":1,
                     "startColumn":1,
                     "endLineNumber":1,
                     "endColumn":84
                  },
                  "text":"Inserted text "
               }
            ]
         }
      ]
   },
   
   "kind":"quickfix"
}

and Here is what monaco expecting to receive:

 {
          title: `Example quick fix`,
          diagnostics: [error],
          kind: "quickfix",
          edit: {
            edits: [
              {
                edit: myedits,
                resource : model.uri
              }
            ]
          },
          isPreferred: true
        };
      });

the difference is between edit.edits.edits and edit.edits.edit the last key has no s.

I am receiving this message when using the converter
Error: bad edit - only text edits are supported

@rcjsuen
Copy link
Contributor

rcjsuen commented Jun 8, 2020

@zkrami Sorry, but I'm having troubles following. Can you provide some more context?

The client is sending your server a textDocument/codeAction request?

@zkrami
Copy link
Author

zkrami commented Jun 8, 2020

Actually I am providing the codeAction to the client to enable quick fix feature in monaco

I hope this snapcode will make the context a bit clearer

const p2m = new ProtocolToMonacoConverter();

  monaco.languages.registerCodeActionProvider(LANGUAGE_ID, {
    provideCodeActions: (model, _range, context, token) => {
      const actions = context.markers.map(marker => m2p.asDiagnostic(marker)).map(diagnostic => {

        return p2m.asCodeAction(formulaLanguageService.codeAction(document, range, diagnostic,uri));

@rcjsuen
Copy link
Contributor

rcjsuen commented Jun 8, 2020

Here is the structure I am receiving:

 {
   "title":"Replace VLOOKUP",
   "edit":{
      "edits":[
         {
            "resource":{            
            },
            "edits":[
               {
                  "range":{
                     "startLineNumber":1,
                     "startColumn":1,
                     "endLineNumber":1,
                     "endColumn":84
                  },
                  "text":"Inserted text "
               }
            ]
         }
      ]
   },
   
   "kind":"quickfix"
}

@zkrami How are you getting this? I don't see anything in your seven lines of code that would correspond to that?

formulaLanguageService.codeAction(document, range, diagnostic,uri)

None of the four arguments here looks like they are related to the above JSON blob.

@zkrami
Copy link
Author

zkrami commented Jun 8, 2020

Actually that's the result of ProtocolToMonacoConverter.asCodeAction
it's related to the returned value.
here is what I am returning from my function.

import { TextEdit, Position, TextDocument, FormattingOptions, Range, Diagnostic, CodeAction, TextDocumentEdit, WorkspaceEdit, Command } from 'vscode-languageserver-protocol';

	codeAction(document: TextDocument, range: Range, error: Diagnostic, uri: string): CodeAction | Command {

		let edits = [TextEdit.replace(range, "Inserted text ")];
		let action = CodeAction.create("Replace VLOOKUP", { changes: { uri: edits } }, "quickfix");
		action.diagnostics = [error] ;


		return action
	}

@rcjsuen
Copy link
Contributor

rcjsuen commented Jun 8, 2020

Here is the structure I am receiving:

 {
   "title":"Replace VLOOKUP",
   "edit":{
      "edits":[
         {
            "resource":{            
            },
            "edits":[
               {
                  "range":{
                     "startLineNumber":1,
                     "startColumn":1,
                     "endLineNumber":1,
                     "endColumn":84
                  },
                  "text":"Inserted text "
               }
            ]
         }
      ]
   },
   
   "kind":"quickfix"
}

@zkrami Your resource looks weird. It shouldn't be an empty object. Step into the asCodeAction function and see what's happening.

@rcjsuen
Copy link
Contributor

rcjsuen commented Jun 8, 2020

@zkrami You should also validate what your custom codeAction function is returning.

@joe-re
Copy link

joe-re commented Jul 5, 2020

@rcjsuen Hi, I'm facing the same problem.

I've implemented websocket connection as follows https://github.com/TypeFox/monaco-languageclient/tree/master/example.

request:

{
  "jsonrpc": "2.0",
  "id": 7,
  "method": "textDocument/codeAction",
  "params": {
    "textDocument": {
      "uri": "inmemory://model.sql"
    },
    "range": {
      "start": {
        "line": 0,
        "character": 0
      },
      "end": {
        "line": 0,
        "character": 0
      }
    },
    "context": {
      "diagnostics": [
        {
          "range": {
            "start": {
              "line": 0,
              "character": 0
            },
            "end": {
              "line": 0,
              "character": 6
            }
          },
          "message": "A linebreak is required after SELECT keyword",
          "severity": 1,
          "source": "sql"
        }
      ]
    }
  }
}
{
  "jsonrpc": "2.0",
  "id": 7,
  "result": [
    {
      "title": "fix: A linebreak is required after SELECT keyword",
      "edit": {
        "documentChanges": [
          {
            "textDocument": {
              "uri": "inmemory://model.sql",
              "version": 1
            },
            "edits": [
              {
                "range": {
                  "start": {
                    "line": 0,
                    "character": 6
                  },
                  "end": {
                    "line": 0,
                    "character": 7
                  }
                },
                "newText": "\n"
              },
              {
                "range": {
                  "start": {
                    "line": 0,
                    "character": 7
                  },
                  "end": {
                    "line": 0,
                    "character": 7
                  }
                },
                "newText": "  "
              }
            ]
          }
        ]
      },
      "kind": "quickfix",
      "diagnostics": [
        {
          "range": {
            "start": {
              "line": 0,
              "character": 0
            },
            "end": {
              "line": 0,
              "character": 6
            }
          },
          "message": "A linebreak is required after SELECT keyword",
          "severity": 1,
          "source": "sql"
        }
      ]
    }
  ]
}

The reproducible code is here.
https://github.com/joe-re/sql-language-server/tree/monaco-editor-example/packages/server/example/monaco_editor

Actually it looks the error from monaco-editor though, is there any possibility monaco-languageclient's fault?
At least it works on vscode and it's a weird point..

@rcjsuen
Copy link
Contributor

rcjsuen commented Jul 6, 2020

The reproducible code is here.
https://github.com/joe-re/sql-language-server/tree/monaco-editor-example/packages/server/example/monaco_editor

@joe-re Your code doesn't compile for me for whatever reason.

git/sql-language-server/packages/server $ npm install
npm WARN prepublish-on-install As of npm@5, `prepublish` scripts are deprecated.
npm WARN prepublish-on-install Use `prepare` for build steps and `prepublishOnly` for upload-only.
npm WARN prepublish-on-install See the deprecation note in `npm help scripts` for more information.

> sql-language-server@0.10.0 prepublish git\sql-language-server\packages\server
> yarn compile:sqlint && yarn compile:cli && yarn compile:index

yarn run v1.22.4
$ cd ../sqlint && yarn build
$ rm -rf dist && rollup -c
[!] Error: Cannot find module '@rollup/plugin-typescript'
Require stack:
- git\sql-language-server\packages\sqlint\rollup.config.js
- git\sql-language-server\packages\server\node_modules\rollup\dist\shared\loadConfigFile.js
- git\sql-language-server\packages\server\node_modules\rollup\dist\bin\rollup
Error: Cannot find module '@rollup/plugin-typescript'
Require stack:
- git\sql-language-server\packages\sqlint\rollup.config.js
- git\sql-language-server\packages\server\node_modules\rollup\dist\shared\loadConfigFile.js
- git\sql-language-server\packages\server\node_modules\rollup\dist\bin\rollup
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
    at Function.Module._load (internal/modules/cjs/loader.js:840:27)
    at Module.require (internal/modules/cjs/loader.js:1019:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (git\sql-language-server\packages\sqlint\rollup.config.js:7:34)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.require.extensions.<computed> [as .js] (git\sql-language-server\packages\server\node_modules\rollup\dist\shared\loadConfigFile.js:557:20)        
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1019:19)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sql-language-server@0.10.0 prepublish: `yarn compile:sqlint && yarn compile:cli && yarn compile:index`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sql-language-server@0.10.0 prepublish script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     AppData\Roaming\npm-cache\_logs\2020-07-06T02_56_45_250Z-debug.log

@joe-re
Copy link

joe-re commented Jul 6, 2020

@rcjsuen Umm looks module installation has failed.
Could you do yarn install on the project root directory and try it again after that?

@rcjsuen
Copy link
Contributor

rcjsuen commented Jul 6, 2020

Could you do yarn install on the project root directory and try it again after that?

@joe-re That got me a little bit further, thanks. I opened joe-re/sql-language-server#41 about that.

I also hit another error while trying to run your example, see joe-re/sql-language-server#37 (review).

@rcjsuen
Copy link
Contributor

rcjsuen commented Jul 6, 2020

@joe-re Your error is due to your usage of Monaco Editor 0.20 with monaco-languageclient 0.13.0. You don't have the fixes from #207 so the integration is not working properly.

@joe-re
Copy link

joe-re commented Jul 6, 2020

@rcjsuen Oh, I see. I got succeeded after updating monaco-languageclient version to ^0.13.1-next.1. Thank you for your help!

joe-re added a commit to joe-re/sql-language-server that referenced this issue Jul 6, 2020
@rcjsuen
Copy link
Contributor

rcjsuen commented Jul 6, 2020

@rcjsuen Oh, I see. I got succeeded after updating monaco-languageclient version to ^0.13.1-next.1. Thank you for your help!

@joe-re Happy to help and glad to hear that upgrading resolved it. More people testing and validating the fix is always good! :) Good luck with your project!

@stale
Copy link

stale bot commented Sep 5, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 5, 2020
@stale stale bot closed this as completed Sep 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants