ghdl / ghdl-language-server

Language server based on ghdl
MIT License
92 stars 8 forks source link

[Bug] Cannot read property 'capabilities' of null when running GHDL-LS LSP Server #73

Open pidgeon777 opened 3 years ago

pidgeon777 commented 3 years ago

We're trying to run ghdl-ls on Neovim with coc.nvim, one of its LSP clients.

An error occurs when doing that, we're trying to understand if this is a bug coc.nvim side or ghdl-ls side.

Here is the necessary info:

Result from CocInfo

## versions

vim version: NVIM v0.4.4
node version: v14.15.4
coc.nvim version: 0.0.80-50544406f0
coc.nvim directory: C:\Neovim\config\nvim\plugged\coc.nvim
term: undefined
platform: win32

## Log of coc.nvim

2021-01-31T15:54:27.641 INFO (pid:24080) [services] - registered service "languageserver.ghdlLS"
2021-01-31T15:54:27.883 INFO (pid:24080) [plugin] - coc.nvim 0.0.80-50544406f0 initialized with node: v14.15.4 after 308ms
2021-01-31T15:54:30.772 INFO (pid:24080) [attach] - receive notification: showInfo []

Describe the bug

I defined a LSP entry in the coc-settings.json file, this involve running the ghdl-ls executable when analyzing VHDL files. When one of those VHDL files is opened, coc.nvim detect it and start the ghdl-ls LSP Server, but an error is generated, the following:

Cannot read property 'capabilities' of null

I'm using other VHDL LSP Servers with success, which are currently disabled, but this issue only occurs when using ghdl-ls.

Reproduce the bug

let s:ghdl_p = 'C:\GHDL\bin' let s:ghdl_ls_p = 'C:\Users\pcuser.local\bin'

if (has('win32') || has('win64')) if !executable('ghdl') if (isdirectory(s:ghdl_p)) let $PATH .= ';' . s:ghdl_p endif endif

if !executable('ghdl-ls') if (isdirectory(s:ghdl_ls_p)) let $PATH .= ';' . s:ghdl_ls_p endif endif

endif

" -----------------------------

set nocompatible set runtimepath^=C:\Neovim\config\nvim\plugged\coc.nvim filetype plugin indent on syntax on set hidden


- Start (neo)vim with command: `vim -u mini.vim`

- Operate vim.

My `coc-settings.json`:

````json
{
    "suggest.autoTrigger": "always",

    "diagnostic.messageDelay": 0,

    "suggest.triggerCompletionWait" : 30,
    "signature.triggerSignatureWait": 200,

    "languageserver": {
        "ghdlLS": {
            "enable": true,
            "trace.server": "verbose",
            "command": "ghdl-ls",
            "filetypes": [
                "vhdl"
            ],
                        "trace.server": "verbose"
        }
    },

    "snippets.userSnippetsDirectory": "$VIMCONFIG/UltiSnips"
}

LSP server config file hdl-prj.json:

{
    "options": {
        "ghdl_analysis": [
            "--workdir=work",
            "--ieee=synopsys",
            "-fexplicit"
        ]
    },
    "files": [
        { "file": "C:/VHDL/entity.vhd", "language": "vhdl" }
    ]
}

hdl-prj.json path:

C:\Test\hdl-prj.json

set pwd? result in Neovim:

C:\Test

ghdl-ls manual execution test in Neovim:

:!ghdl-ls --version
ghdl-ls 1.0-dev

The Issue

It occurs when I load the file added to the LSP config project, or any file of the VHDL type.

Coc.nvim returns:

[coc.nvim] Caught exception while handling initialize, see VHDL language server output for details.
[coc.nvim] Cannot read property 'capabilities' of null
[coc.nvim] Server languageserver.ghdlLS failed to start: TypeError: Cannot read property 'capabilities' of null

CocCommand workspace.showOutput shows an empty buffer.

pidgeon777 commented 3 years ago

Here is the issue created on coc.nvim repository:

https://github.com/neoclide/coc.nvim/issues/2859

tgingold commented 3 years ago

It looks like that's 'capabilities' from the client that generates the error.

Can you log the whole exchange ? Just use: export GHDL_LS_TRACE=ghdl-ls This will create two files.

pidgeon777 commented 3 years ago

Pardon me, where should I put that command? For example:

and where should I expect the files to be generated?

tgingold commented 3 years ago

It's a shell command, so set the variable before invoking nvim. The files are created in the current directory.

tgingold commented 3 years ago

If you are using windows, you can also add the option '--trace-file=ghdl-ls' when invoking the ghdl-ls server.

pidgeon777 commented 3 years ago

I've to add that I'm currently running a ghdl-ls executable which I just built on my Windows 10 machine. I'm able to run it without any shell, just Windows 10 Command Prompt:

image

pidgeon777 commented 3 years ago

If you are using windows, you can also add the option '--trace-file=ghdl-ls' when invoking the ghdl-ls server.

Sorry, I just noticed your post. I'll try right now.

pidgeon777 commented 3 years ago

ghdl-ls.in:

Content-Length: 3023

{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":17560,"rootPath":"C:\\Test","rootUri":"file:///c%3A/Test","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"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]},"tagSupport":{"valueSet":[1]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":true,"versionSupport":false,"tagSupport":{"valueSet":[1,2]}},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true,"tagSupport":{"valueSet":[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]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"contextSupport":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"],"activeParameterSupport":true,"parameterInformation":{"labelOffsetSupport":true}}},"definition":{"dynamicRegistration":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"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]},"hierarchicalDocumentSymbolSupport":true,"tagSupport":{"valueSet":[1]}},"codeAction":{"dynamicRegistration":true,"isPreferredSupport":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"documentLink":{"dynamicRegistration":true,"tooltipSupport":true},"typeDefinition":{"dynamicRegistration":true},"implementation":{"dynamicRegistration":true},"declaration":{"dynamicRegistration":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true},"selectionRange":{"dynamicRegistration":true}},"window":{"workDoneProgress":true}},"initializationOptions":{},"trace":"verbose","workspaceFolders":[],"clientInfo":{"name":"coc.nvim","version":"0.0.80"},"workDoneToken":"b17acdbd-f76c-47b8-b4cb-559c9513315f"}}Content-Length: 58

{"jsonrpc":"2.0","id":1,"method":"shutdown","params":null}

ghdl-ls.out:

Content-Length: 168

{"jsonrpc":"2.0","method":"window/showMessage","params":{"type":1,"message":"Caught exception while handling initialize, see VHDL language server output for details."}}Content-Length: 38

{"jsonrpc":"2.0","id":0,"result":null}Content-Length: 38

{"jsonrpc":"2.0","id":1,"result":null}
tgingold commented 3 years ago

I have the impression you didn't install the libraries. You should first install ghdl before installing the LSP server.

If this is the case, the error message has to be improved.

pidgeon777 commented 3 years ago

I already built GHDL through MSYS2. Here is some info regarding the built executable:

C:\GHDL\bin>ghdl --version
GHDL 1.0-dev (tarball) [Dunoon edition]
 Compiled with GNAT Version: 10.2.0
 mcode code generator
Written by Tristan Gingold.

Copyright (C) 2003 - 2021 Tristan Gingold.
GHDL is free software, covered by the GNU General Public License.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

C:\GHDL\bin>ghdl --disp-config
command_name: C:\GHDL\bin\ghdl.exe
command line prefix (--PREFIX): (not set)
environment prefix (GHDL_PREFIX): (not set)
exec prefix (from program name): C:\GHDL

library prefix: C:\GHDL\lib/ghdl
library directory: C:\GHDL\lib/ghdl
default library paths:
 C:\GHDL\lib/ghdl\ieee\v93\
 C:\GHDL\lib/ghdl\

I'm happy to provide all of the necessary info and conducts tests to solve this issue. I would really like to try the GHDL LSP Server on Neovim.

tgingold commented 3 years ago

The ghdl executable looks correctly built and installed. But that's not the case for ghdl-ls.exe. It returns a weird prefix: /c/GHDL\lib\ghdl

tgingold commented 3 years ago

So I suppose you configured ghdl using --prefix=/c/GHDL You should try with a windows path: --prefix=C:\\GHDL

pidgeon777 commented 3 years ago

Ok, I tried some combinations and this worked:

--prefix=C:/GHDL

I think the documentation should be updated too, where the prefix part is cited:

https://github.com/ghdl/ghdl

The executable is installed as 'ghdl' in /usr/local. To install it to a different path, change the --prefix in the call to configure. For example, on Windows, you may want to set it to --prefix=/c/Program Files (x86)/GHDL.

The great news is that I'm finally able to run ghdl-ls in Neovim, on my Windows machine.

Here is the new ghdl-ls --disp.config output:

command line prefix (--PREFIX): (not set)
environment prefix (GHDL_PREFIX): (not set)
exec prefix (from program name): C:\msys64\mingw64

library prefix: C:/GHDL\lib/ghdl
library directory: C:/GHDL\lib/ghdl

and ghdl-ls --version:

ghdl-ls 1.0.0rc3

Apparently and interestingly, it has been updated from 1.0-dev to 1.0.0rc3 in the last few hours.

I've already conducted some tests, should I open a new issue to discuss them?

In the meanwhile, my most sincere thanks for your help.

eine commented 3 years ago

@pidgeon777, on MSYS2, it should work without manually building GHDL:

pacman -S mingw-w64-ghdl-llvm mingw-w64-python-pip
pip install git+https://github.com/ghdl/ghdl.git@$(ghdl version hash)

You can open any other terminal/tool from there (cmd, powershell) for inheriting the environment.

That's how I use the VSCode extension.