ndonfris / fish-lsp

LSP implementation for the fish shell langauge 🐠
https://fish-lsp.dev
MIT License
97 stars 6 forks source link

fish-lsp crashes soon after startup #28

Closed kmoschcau closed 5 months ago

kmoschcau commented 5 months ago

When I open my fish config in nvim with fish-lsp set up via nvim-lspconfig, the server soon crashes with the following error:

RPC[Error] code_name = InternalError, message = "Request initialize failed with message: Command failed: abbr --show | string split ' -- ' -m1 -f2 | string unescape\n

Here is the relevant LSP log:

[DEBUG][2024-06-03 09:02:54] .../vim/lsp/rpc.lua:408    "rpc.receive"   {  jsonrpc = "2.0",  method = "window/logMessage",  params = {    message = 'Initialized server FISH-LSP with {"processId":48580,"capabilities":{"window":{"workDoneProgress":true,"showDocument":{"support":true},"showMessage":{"messageActionItem":{"additionalPropertiesSupport":false}}},"general":{"positionEncodings":["utf-16"]},"textDocument":{"references":{"dynamicRegistration":false},"implementation":{"linkSupport":true},"rangeFormatting":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":false},"completion":{"contextSupport":true,"completionItem":{"insertReplaceSupport":true,"deprecatedSupport":true,"insertTextModeSupport":{"valueSet":[1,2]},"resolveSupport":{"properties":["documentation","detail","additionalTextEdits","sortText","filterText","insertText","textEdit","insertTextFormat","insertTextMode"]},"commitCharactersSupport":true,"tagSupport":{"valueSet":[1]},"snippetSupport":true,"preselectSupport":true,"labelDetailsSupport":true,"documentationFormat":["markdown","plaintext"]},"dynamicRegistration":false,"completionList":{"itemDefaults":["commitCharacters","editRange","insertTextFormat","insertTextMode","data"]},"insertTextMode":1,"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"diagnostic":{"dynamicRegistration":false},"formatting":{"dynamicRegistration":true},"semanticTokens":{"serverCancelSupport":false,"requests":{"range":false,"full":{"delta":true}},"formats":["relative"],"tokenTypes":["namespace","type","class","enum","interface","struct","typeParameter","parameter","variable","property","enumMember","event","function","method","macro","keyword","modifier","comment","string","number","regexp","operator","decorator"],"overlappingTokenSupport":true,"dynamicRegistration":false,"augmentsSyntaxTokens":true,"multilineTokenSupport":false,"tokenModifiers":["declaration","definition","readonly","static","deprecated","abstract","async","modification","documentation","defaultLibrary"]},"publishDiagnostics":{"dataSupport":true,"relatedInformation":true,"tagSupport":{"valueSet":[1,2]}},"rename":{"dynamicRegistration":true,"prepareSupport":true},"declaration":{"linkSupport":true},"inlayHint":{"dynamicRegistration":true,"resolveSupport":{"properties":["textEdits","tooltip","location","command"]}},"definition":{"dynamicRegistration":true,"linkSupport":true},"callHierarchy":{"dynamicRegistration":false},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":false,"signatureInformation":{"parameterInformation":{"labelOffsetSupport":true},"activeParameterSupport":true,"documentationFormat":["markdown","plaintext"]}},"documentSymbol":{"hierarchicalDocumentSymbolSupport":true,"dynamicRegistration":false,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"codeAction":{"dataSupport":true,"resolveSupport":{"properties":["edit"]},"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"dynamicRegistration":true,"isPreferredSupport":true},"typeDefinition":{"linkSupport":true},"synchronization":{"willSaveWaitUntil":true,"willSave":true,"dynamicRegistration":false,"didSave":true}},"workspace":{"symbol":{"dynamicRegistration":false,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"workspaceEdit":{"resourceOperations":["rename","create","delete"]},"didChangeWatchedFiles":{"dynamicRegistration":false,"relativePatternSupport":true},"inlayHint":{"refreshSupport":true},"workspaceFolders":true,"didChangeConfiguration":{"dynamicRegistration":false},"semanticTokens":{"refreshSupport":true},"applyEdit":true,"configuration":true}},"workspaceFolders":[{"uri":"file:///home/kmoschcau/.config/fish","name":"/home/kmoschcau/.config/fish"}],"rootUri":"file:///home/kmoschcau/.config/fish","trace":"off","initializationOptions":{},"clientInfo":{"name":"Neovim","version":"0.11.0-dev"},"rootPath":"/home/kmoschcau/.config/fish"}',    type = 4  }}
[INFO][2024-06-03 09:02:54] ...lsp/handlers.lua:628 'Initialized server FISH-LSP with {"processId":48580,"capabilities":{"window":{"workDoneProgress":true,"showDocument":{"support":true},"showMessage":{"messageActionItem":{"additionalPropertiesSupport":false}}},"general":{"positionEncodings":["utf-16"]},"textDocument":{"references":{"dynamicRegistration":false},"implementation":{"linkSupport":true},"rangeFormatting":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":false},"completion":{"contextSupport":true,"completionItem":{"insertReplaceSupport":true,"deprecatedSupport":true,"insertTextModeSupport":{"valueSet":[1,2]},"resolveSupport":{"properties":["documentation","detail","additionalTextEdits","sortText","filterText","insertText","textEdit","insertTextFormat","insertTextMode"]},"commitCharactersSupport":true,"tagSupport":{"valueSet":[1]},"snippetSupport":true,"preselectSupport":true,"labelDetailsSupport":true,"documentationFormat":["markdown","plaintext"]},"dynamicRegistration":false,"completionList":{"itemDefaults":["commitCharacters","editRange","insertTextFormat","insertTextMode","data"]},"insertTextMode":1,"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"diagnostic":{"dynamicRegistration":false},"formatting":{"dynamicRegistration":true},"semanticTokens":{"serverCancelSupport":false,"requests":{"range":false,"full":{"delta":true}},"formats":["relative"],"tokenTypes":["namespace","type","class","enum","interface","struct","typeParameter","parameter","variable","property","enumMember","event","function","method","macro","keyword","modifier","comment","string","number","regexp","operator","decorator"],"overlappingTokenSupport":true,"dynamicRegistration":false,"augmentsSyntaxTokens":true,"multilineTokenSupport":false,"tokenModifiers":["declaration","definition","readonly","static","deprecated","abstract","async","modification","documentation","defaultLibrary"]},"publishDiagnostics":{"dataSupport":true,"relatedInformation":true,"tagSupport":{"valueSet":[1,2]}},"rename":{"dynamicRegistration":true,"prepareSupport":true},"declaration":{"linkSupport":true},"inlayHint":{"dynamicRegistration":true,"resolveSupport":{"properties":["textEdits","tooltip","location","command"]}},"definition":{"dynamicRegistration":true,"linkSupport":true},"callHierarchy":{"dynamicRegistration":false},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":false,"signatureInformation":{"parameterInformation":{"labelOffsetSupport":true},"activeParameterSupport":true,"documentationFormat":["markdown","plaintext"]}},"documentSymbol":{"hierarchicalDocumentSymbolSupport":true,"dynamicRegistration":false,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"codeAction":{"dataSupport":true,"resolveSupport":{"properties":["edit"]},"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"dynamicRegistration":true,"isPreferredSupport":true},"typeDefinition":{"linkSupport":true},"synchronization":{"willSaveWaitUntil":true,"willSave":true,"dynamicRegistration":false,"didSave":true}},"workspace":{"symbol":{"dynamicRegistration":false,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"workspaceEdit":{"resourceOperations":["rename","create","delete"]},"didChangeWatchedFiles":{"dynamicRegistration":false,"relativePatternSupport":true},"inlayHint":{"refreshSupport":true},"workspaceFolders":true,"didChangeConfiguration":{"dynamicRegistration":false},"semanticTokens":{"refreshSupport":true},"applyEdit":true,"configuration":true}},"workspaceFolders":[{"uri":"file:///home/kmoschcau/.config/fish","name":"/home/kmoschcau/.config/fish"}],"rootUri":"file:///home/kmoschcau/.config/fish","trace":"off","initializationOptions":{},"clientInfo":{"name":"Neovim","version":"0.11.0-dev"},"rootPath":"/home/kmoschcau/.config/fish"}'
[DEBUG][2024-06-03 09:02:54] .../vim/lsp/rpc.lua:408    "rpc.receive"   {  error = {    code = -32603,    message = "Request initialize failed with message: Command failed: abbr --show | string split ' -- ' -m1 -f2 | string unescape\n"  },  id = 1,  jsonrpc = "2.0"}

Running abbr --show in my shell returns an empty output. Which in turn causes both string split and string unescape to return with exit code 1.

(PS: You might want to add another issue template for bug reports, besides feature requests and security vulnerabilities.)

ndonfris commented 5 months ago

Thanks for the feedback, will add some more templates to the project tonight.

Currently, I'm a little preoccupied with adding more extensive test coverage, to catch edge cases like this. Having said that, I will work on producing a fix when I get a chance.

Feel free to submit a PR, if you find a quick way to build the abbr completions, without exiting on stderr when there are no abbreviations.

I believe the file producing this error is src/utils/completions/startup-config.ts

In the meantime, I believe if you add any abbr to your config.fish, it should remove this error. I highly encourage their usage. Just incase you wanted to try a couple out, here are some examples:

PeterCardenas commented 5 months ago

i do use abbr but i gate them behind the is-interactive flag. i guess the suggestion here is to enable override this for fish lsp?

ndonfris commented 5 months ago

So your setup looks something like the following?

if status is-interactive
     abbr --add gco git checkout
end

Assuming I understand the purpose behind this setup, do you think this project should consider itself as an interactive process (i.e., parsing out the relevant abbr commands, and attempting to build them for the user's completion list)? Or, are only some of your abbreviations included here, and these should be ignored by the lsp?

PeterCardenas commented 5 months ago

all of my abbr are gated since non-interactive sessions can’t use abbreviations i believe

PeterCardenas commented 5 months ago

it would be cool if the lsp handled this but i think it’s also reasonable to just recommend adding an env var

ndonfris commented 5 months ago

Thanks for the feedback.

Currently, the fish-lsp, does build abbreviations for the completion list, and uses them in non-interactive sessions (although the newer releases to the abbr command like --set-cursor and --position are not supported).

Theoretically, tree-sitter could gather all the abbr commands, and build equivalent completions. Trying to build that would be difficult, though.

For now, I am testing this command:

[ (abbr --show | count) -eq 0 ] ||  abbr --show | string split ' -- ' -m1 -f2 | string unescape

Which I believe should work. LMK, if y'all come up with something shorter.

PeterCardenas commented 5 months ago

can confirm that after i add an abbr and an alias i'm able to start the lsp!! looking into how we can handle this case of no alias or abbr

PeterCardenas commented 5 months ago

rip what are the odds that i comment at the exact same time

PeterCardenas commented 5 months ago

have a patch that has the env var i referenced which is working. however this makes me think that it would be better for the lsp to do the retrieval of the functions/aliases rather than fish to do it. that way i don't have to add this flag everywhere

ndonfris commented 5 months ago

Good tip about the aliases too, Added the relevant fix/no-abbrs-causing-crash

[ (alias | count) -eq 0 ] || alias | string collect | string unescape | string split ' ' -m1 -f2

Could you link me to the env fix?

ndonfris commented 5 months ago

we're synced up on these comment times :rofl:

Is there a good way to start fish in subshell, with a different profile? Something like:

fish --profile=$HOME/.config/empty-fish-config/

Would make testing this way easier

PeterCardenas commented 5 months ago

after scanning the documentation really quickly i don't think so, however we can probably just source <path to config>?

lemme setup a fork rq to share the patch better

PeterCardenas commented 5 months ago

also my autofixer is changing all the files like willy nilly, would you be opposed to adding some pre push hook or github actions to format/lint the files

ndonfris commented 5 months ago

Nah I'm all for that. I do have an action setup for lint, and husky is included. Maybe one of those dependencies didn't get installed correct? I've had husky need extra steps before.

If you're writing a github action, it's a little tricky because the yarn install scripts need fish to execute the scripts/* files for setting up the project.

kmoschcau commented 5 months ago

Yep the server starts now, thanks.