ghdl / ghdl-language-server

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

ghdl-ls Traceback on Windows #172

Open gralco opened 10 months ago

gralco commented 10 months ago

Description After installing ghdl using the latest commit, attempting to run ghdl-ls on Windows fails (tested on Fedora and it works fine).

Context

Here's the traceback I get when trying to run ghdl-ls:

$ ghdl-ls
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "%LOCALAPPDATA%\Programs\Python\Python312\Scripts\ghdl-ls.exe\__main__.py", line 4, in <module>
  File "%LOCALAPPDATA%\Programs\Python\Python312\Lib\site-packages\pyGHDL\cli\lsp.py", line 58, in <module>
    from pyGHDL.lsp.vhdl_ls import VhdlLanguageServer
  File "%LOCALAPPDATA%\Programs\Python\Python312\Lib\site-packages\pyGHDL\lsp\vhdl_ls.py", line 4, in <module>
    from .workspace import Workspace
  File "%LOCALAPPDATA%\Programs\Python\Python312\Lib\site-packages\pyGHDL\lsp\workspace.py", line 12, in <module>
    import pyGHDL.libghdl.vhdl.nodes as nodes
  File "%LOCALAPPDATA%\Programs\Python\Python312\Lib\site-packages\pyGHDL\libghdl\vhdl\nodes.py", line 3662, in <module>
    @BindToLibGHDL("vhdl__nodes__get_mode_view_indication")
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "%LOCALAPPDATA%\Programs\Python\Python312\Lib\site-packages\pyGHDL\libghdl\_decorator.py", line 161, in wrapper
    functionPointer = getattr(libghdl, subprogramName)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "%LOCALAPPDATA%\Programs\Python\Python312\Lib\ctypes\__init__.py", line 392, in __getattr__
    func = self.__getitem__(name)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "%LOCALAPPDATA%\Programs\Python\Python312\Lib\ctypes\__init__.py", line 397, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: function 'vhdl__nodes__get_mode_view_indication' not found. Did you mean: 'vhdl__nodes__get_subtype_indication'?
tgingold commented 10 months ago

Hello,

you need to update libghdl: just re-install ghdl.

Your issue is a little bit weird: you have updated ghdl-language-server, you have update pyGHDL from ghdl, but the libghdl dll has not been updated.

gralco commented 10 months ago

I managed to build ghdl from source, but I first had to fix this:

$HOME/ghdl/src/grt/config/win32.c:183: undefined reference to `__intrinsic_setjmpex'
collect2.exe: error: ld returned 1 exit status
gnatlink: error when calling C:\msys64\mingw64\bin\gcc.exe
gnatmake: *** link failed.
make: *** [Makefile:217: ghdl_mcode.exe] Error 4

By changing #include <setjmp.h> with #include <setjmpex.h> in ghdl/src/grt/config/win32.c (as suggested here).

gralco commented 10 months ago

For reference, in order to make ghdl-ls to function within neovim I needed to add the following in my init.lua file:

if not require'lspconfig.configs'.ghdl_ls then
  require'lspconfig.configs'.ghdl_ls = {
    default_config = {
      cmd = {"ghdl-ls"};
      filetypes = {"vhdl"};
      root_dir = function(fname)
        local util = require'lspconfig'.util
        return vim.fs.dirname(vim.fs.find({'hdl-prj.json'}, {upward=true})[1]) or util.root_pattern('hdl-prj.json')(fname) or util.find_git_ancestor(fname) or vim.fn.getcwd() or util.path.dirname(fname) 
      end;
      settings = {};
    };
  }
end

require'lspconfig'.ghdl_ls.setup{}

Otherwise it the LSP will not be able to find / hook onto the root directory where the vhdl code is located. Doing single_file_mode = true is not enough to make it work.

tgingold commented 10 months ago

Is the dll path correct and does it exist?

If yes, the error is probably due to a dependency (libgcc or libgnat). You need to update PATH.

gralco commented 10 months ago

Is the dll path correct and does it exist? If yes, the error is probably due to a dependency (libgcc or libgnat). You need to update PATH.

I managed to fix that by building ghdl from source.

gralco commented 10 months ago

I somehow ran into this issue again. As it turns out, what I needed to do was to copy over my built libghdl-4_0_0_dev.dll into /c/msys64/mingw64/lib/libghdl-4_0_0_dev.dll, that's where it's looking for libghdl (where there was an old libghdl.dll that wasn't updated when doing make install).

gralco commented 10 months ago

On Fedora 38 the libghdl-4_0_0_dev.so that's built needs to be in ~/.local/lib/.