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

Missing Code Actions for TypeScript LSP #2994

Closed
hovsater opened this issue Jul 7, 2022 · 7 comments · Fixed by #3096
Closed

Missing Code Actions for TypeScript LSP #2994

hovsater opened this issue Jul 7, 2022 · 7 comments · Fixed by #3096
Labels
A-language-server Area: Language server client C-bug Category: This is a bug

Comments

@hovsater
Copy link
Contributor

hovsater commented Jul 7, 2022

Summary

No code actions are available at places where one expect code actions to be available. I've created this repo to showcase the problem. See the attached videos below in which I compare Sublime Text and Helix.

Sublime Text

sublime.mov

Helix

helix.mov

Reproduction Steps

  1. Git clone https://github.com/kevinsjoberg/helix-ts-testcase
  2. Follow the steps in the README.

Helix log

~/.cache/helix/helix.log
2022-07-07T12:00:31.394 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"completion":{"completionItem":{"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]},"snippetSupport":false},"completionItemKind":{}},"hover":{"contentFormat":["markdown"]},"publishDiagnostics":{},"rename":{"dynamicRegistration":false,"honorsChangeAnnotations":false,"prepareSupport":false}},"window":{"workDoneProgress":true},"workspace":{"configuration":true,"didChangeConfiguration":{"dynamicRegistration":false},"workspaceFolders":true}},"processId":29702,"rootPath":"/Users/kevin/code/helix-ts-testcase","rootUri":"file:///Users/kevin/code/helix-ts-testcase","workspaceFolders":[{"name":"helix-ts-testcase","uri":"file:///Users/kevin/code/helix-ts-testcase"}]},"id":0}
2022-07-07T12:00:31.548 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"[lspserver] Using Typescript version (workspace) 4.7.4 from path \"/Users/kevin/code/helix-ts-testcase/node_modules/typescript/lib/tsserver.js\""}}
2022-07-07T12:00:31.548 helix_term::application [INFO] window/logMessage: LogMessageParams { typ: Info, message: "[lspserver] Using Typescript version (workspace) 4.7.4 from path \"/Users/kevin/code/helix-ts-testcase/node_modules/typescript/lib/tsserver.js\"" }
2022-07-07T12:00:31.673 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","id":0,"result":{"capabilities":{"textDocumentSync":2,"completionProvider":{"triggerCharacters":[".","\"","'","/","@","<"],"resolveProvider":true},"codeActionProvider":{"codeActionKinds":["source.fixAll.ts","source.removeUnused.ts","source.addMissingImports.ts","source.organizeImports.ts"]},"definitionProvider":true,"documentFormattingProvider":true,"documentRangeFormattingProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"executeCommandProvider":{"commands":["_typescript.applyWorkspaceEdit","_typescript.applyCodeAction","_typescript.applyRefactoring","_typescript.organizeImports","_typescript.applyRenameFile"]},"hoverProvider":true,"renameProvider":true,"referencesProvider":true,"signatureHelpProvider":{"triggerCharacters":["(",",","<"]},"workspaceSymbolProvider":true,"implementationProvider":true,"typeDefinitionProvider":true,"foldingRangeProvider":true,"semanticTokensProvider":{"documentSelector":null,"legend":{"tokenTypes":["class","enum","interface","namespace","typeParameter","type","parameter","variable","enumMember","property","function","member"],"tokenModifiers":["declaration","static","async","readonly","defaultLibrary","local"]},"full":true,"range":true},"callsProvider":true}}}
2022-07-07T12:00:31.673 helix_lsp::transport [INFO] <- {"capabilities":{"callsProvider":true,"codeActionProvider":{"codeActionKinds":["source.fixAll.ts","source.removeUnused.ts","source.addMissingImports.ts","source.organizeImports.ts"]},"completionProvider":{"resolveProvider":true,"triggerCharacters":[".","\"","'","/","@","<"]},"definitionProvider":true,"documentFormattingProvider":true,"documentHighlightProvider":true,"documentRangeFormattingProvider":true,"documentSymbolProvider":true,"executeCommandProvider":{"commands":["_typescript.applyWorkspaceEdit","_typescript.applyCodeAction","_typescript.applyRefactoring","_typescript.organizeImports","_typescript.applyRenameFile"]},"foldingRangeProvider":true,"hoverProvider":true,"implementationProvider":true,"referencesProvider":true,"renameProvider":true,"semanticTokensProvider":{"documentSelector":null,"full":true,"legend":{"tokenModifiers":["declaration","static","async","readonly","defaultLibrary","local"],"tokenTypes":["class","enum","interface","namespace","typeParameter","type","parameter","variable","enumMember","property","function","member"]},"range":true},"signatureHelpProvider":{"triggerCharacters":["(",",","<"]},"textDocumentSync":2,"typeDefinitionProvider":true,"workspaceSymbolProvider":true}}
2022-07-07T12:00:31.673 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"initialized","params":{}}
2022-07-07T12:00:31.673 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"typescriptreact","text":"import React from \"react\";\n\nexport function App() {\n  const [count, setCount] = useState(0);\n\n  return (\n    <>\n      <h1>Button has been clicked {count} times</h1>\n      <button onClick={() => setCount(prevCount => prevCount + 1)}>Click me!</button>\n    </>\n  );\n}","uri":"file:///Users/kevin/code/helix-ts-testcase/src/App.tsx","version":0}}}
2022-07-07T12:00:31.676 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","id":0,"method":"window/workDoneProgress/create","params":{"token":"910d0956-dab6-4156-a08f-b069a4419676"}}
2022-07-07T12:00:31.676 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","result":null,"id":0}
2022-07-07T12:00:31.677 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"$/progress","params":{"token":"910d0956-dab6-4156-a08f-b069a4419676","value":{"kind":"begin","title":"Initializing JS/TS language features…"}}}
2022-07-07T12:00:32.024 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"$/progress","params":{"token":"910d0956-dab6-4156-a08f-b069a4419676","value":{"kind":"end"}}}
2022-07-07T12:00:32.078 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///Users/kevin/code/helix-ts-testcase/src/App.tsx","diagnostics":[]}}
2022-07-07T12:00:32.163 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///Users/kevin/code/helix-ts-testcase/src/App.tsx","diagnostics":[{"range":{"start":{"line":3,"character":28},"end":{"line":3,"character":36}},"message":"Cannot find name 'useState'.","severity":1,"code":2304,"source":"typescript"},{"range":{"start":{"line":8,"character":38},"end":{"line":8,"character":47}},"message":"Parameter 'prevCount' implicitly has an 'any' type.","severity":1,"code":7006,"source":"typescript"}]}}
2022-07-07T12:00:34.257 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/codeAction","params":{"context":{"diagnostics":[{"message":"Cannot find name 'useState'.","range":{"end":{"character":36,"line":3},"start":{"character":28,"line":3}},"severity":1}]},"range":{"end":{"character":31,"line":3},"start":{"character":28,"line":3}},"textDocument":{"uri":"file:///Users/kevin/code/helix-ts-testcase/src/App.tsx"}},"id":1}
2022-07-07T12:00:34.317 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","id":1,"result":[]}
2022-07-07T12:00:34.317 helix_lsp::transport [INFO] <- []
2022-07-07T12:00:37.055 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"shutdown","params":null,"id":2}
2022-07-07T12:00:37.058 helix_lsp::transport [INFO] <- {"jsonrpc":"2.0","id":2,"result":null}
2022-07-07T12:00:37.058 helix_lsp::transport [INFO] <- null
2022-07-07T12:00:37.058 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"exit","params":null}

Platform

macOS

Terminal Emulator

kitty 0.25.2

Helix Version

helix 22.05 (230ba26)

@hovsater hovsater added the C-bug Category: This is a bug label Jul 7, 2022
@kirawi kirawi added the A-language-server Area: Language server client label Jul 7, 2022
@hovsater
Copy link
Contributor Author

hovsater commented Jul 7, 2022

I've debugged this further. It looks like the range provided is wrong. Compare the code action request from Sublime Text vs the one from Helix.

Sublime Text

{
   "range":{
      "start":{
         "line":3,
         "character":28
      },
      "end":{
         "line":3,
         "character":36
      }
   },
   "context":{
      "diagnostics":[
         {
            "range":{
               "start":{
                  "line":3,
                  "character":28
               },
               "end":{
                  "line":3,
                  "character":36
               }
            },
            "tags":[
               
            ],
            "message":"Cannot find name 'useState'.",
            "code":2304,
            "severity":1,
            "source":"typescript"
         }
      ]
   },
   "textDocument":{
      "uri":"file:///Users/kevin/code/helix-ts-testcase/src/App.tsx"
   }
}

Helix

{
   "jsonrpc":"2.0",
   "method":"textDocument/codeAction",
   "params":{
      "context":{
         "diagnostics":[
            {
               "message":"Cannot find name 'useState'.",
               "range":{
                  "end":{
                     "character":36,
                     "line":3
                  },
                  "start":{
                     "character":28,
                     "line":3
                  }
               },
               "severity":1
            }
         ]
      },
      "range":{
         "end":{
            "character":29,
            "line":3
         },
         "start":{
            "character":28,
            "line":3
         }
      },
      "textDocument":{
         "uri":"file:///Users/kevin/code/helix-ts-testcase/src/App.tsx"
      }
   },
   "id":1
}

@archseer
Copy link
Member

archseer commented Jul 8, 2022

When you were generating the logs, did you make a selection or did you only have a cursor? The logs seem to indicate you just had a 1 character width cursor.

@hovsater
Copy link
Contributor Author

hovsater commented Jul 8, 2022

No selection, just moved to the word useState. Similar to what I do in the video. In any case, given that we have diagnostics for the word under the cursor, I would assume its range would be used?

@archseer
Copy link
Member

archseer commented Jul 8, 2022

We use the range of the selection. Try to make a matching selection.

It could also be fixed by #3012

@erasin
Copy link
Contributor

erasin commented Jul 12, 2022

This problem still exists with TS

@hovsater
Copy link
Contributor Author

@archseer I'm not sure I follow. If the diagnostics point out a problem and I move my cursor somewhere within the diagnostic range, I'd assume the Code Actions apply using the range of the diagnostic. I believe this is how it's implemented in other editors. I've verified that I get the correct behaviour in Vim, Neovim, Sublime Text and VSCode. As long as I'm in within the diagnostic range, the Code Actions are listed as expected.

erasin added a commit to erasin/helix that referenced this issue Jul 18, 2022
This PR provides a solution to resolve helix-editor#2994. missing Code Actions for lsp
@erasin
Copy link
Contributor

erasin commented Jul 18, 2022

WX20220718-234852@2x

thomasskk pushed a commit to thomasskk/helix that referenced this issue Sep 9, 2022
* add code for diagnostic.

This PR provides a solution to resolve helix-editor#2994. missing Code Actions for lsp

* remote unused import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-server Area: Language server client C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants