vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
533 stars 89 forks source link

How to configure Neovim to use asy -lsp? #372

Open kiryph opened 1 year ago

kiryph commented 1 year ago

I have followed :h lspconfig-new of https://github.com/neovim/nvim-lspconfig for Neovim.

https://github.com/neovim/nvim-lspconfig/blob/8cbfc30c4b238cc2465ff256803f7747376f046a/doc/lspconfig.txt#L324-L350

ADDING NEW SERVERS                                    *lspconfig-new*

The steps for adding and enabling a new server configuration are:

1. load the `lspconfig` module (note that this is a stylistic choice)  
   local lspconfig = require 'lspconfig'

2. define the configuration  
   local configs = require 'lspconfig.configs'

   -- Check if the config is already defined (useful when reloading this file)
   if not configs.foo_lsp then
     configs.foo_lsp = {
       default_config = {
         cmd = {'/home/neovim/lua-language-server/run.sh'},
         filetypes = {'lua'},
         root_dir = function(fname)
           return lspconfig.util.find_git_ancestor(fname)
         end,
         settings = {},
       },
     }
   end

3. call `setup()` to enable the FileType autocmd  
   lspconfig.foo_lsp.setup{}

to have in my init.lua using Neovim 0.9:

-- Asymptote LSP
local lspconfig = require 'lspconfig'
local configs = require 'lspconfig.configs'
local util = require 'lspconfig.util'

if not configs.asy_ls then
   configs.asy_ls = {
    default_config = {
      cmd = {'asy', '-lsp'},
      filetypes = {'asy'},
      root_dir = function(fname)
        return util.find_git_ancestor(fname)
      end,
      single_file_support = true,
      settings = {},
    },
  }
end
lspconfig.asy_ls.setup{}

But when I open an asy file, no LSP client gets attached to the buffer

 Press q or <Esc> to close this window. Press <Tab> to view server doc.

 Language client log: /Users/kiryph/.local/state/nvim/lsp.log
 Detected filetype:   asy

 0 client(s) attached to this buffer: 

 Other clients that match the filetype: asy

 Config: asy_ls
    filetypes:         asy
    root directory:    /Users/kiryph/lsp-asy
    cmd:               asy -lsp
    cmd is executable: true
    autostart:         true
    custom handlers:   

and I see following errors in the :LspLog

[START][2023-04-17 10:38:31] LSP logging initiated
[ERROR][2023-04-17 10:38:31] .../vim/lsp/rpc.lua:734    "rpc"   "asy"   "stderr"    "-: 1.15: syntax error"
[ERROR][2023-04-17 10:38:31] .../vim/lsp/rpc.lua:734    "rpc"   "asy"   "stderr"    "\n"

I am not sure who to ask.

My Environment

Asymptote version 2.85
NVIM: v0.9.0
macOS: 12.6.3
CPU: Intel
kiryph commented 1 year ago

Apparently, you have to compile asymptote yourself. The full version info of asymptote gives me for asy from MacTex 2023 and Homebrew:

❯ which -a asy
/usr/local/bin/asy
/Library/TeX/texbin/asy

❯ asy --version
Asymptote version 2.85 [(C) 2004 Andy Hammerlindl, John C. Bowman, Tom Prince]

ENABLED OPTIONS:
V3D      3D vector graphics output
WebGL    3D HTML rendering
OpenGL   3D OpenGL rendering
GSL      GNU Scientific Library (special functions)
FFTW3    Fast Fourier transforms
XDR      External Data Representation (portable binary file format for V3D)
CURL     URL support
Readline Interactive history and editing
GC       Boehm garbage collector
threads  Render OpenGL in separate thread

DISABLED OPTIONS:
SSBO     GLSL shader storage buffer objects
Eigen    Eigenvalue library
LSP      Language Server Protocol
Sigsegv  Distinguish stack overflows from segmentation faults

See LSP entry under DISABLED OPTIONS.

I am surprised that I can invoke asy -lsp without an error which clearly says that LSP is not enabled.

Unfortunately, there are no easy to follow compilation instructions for asymptote on macOS with LSP enabled, e.g.

https://github.com/vectorgraphics/asymptote/issues/304

https://formulae.brew.sh/formula/asymptote

MacPorts also do not offer a variant with LSP enabled: https://ports.macports.org/port/asymptote/

johncbowman commented 1 year ago

In commit 456ae99203a291f9c50128ec55965ad948e11971, I have now removed the lsp option when LSP support is disabled, so that --lsp returns an error (and -lsp is then parsed as -l -s -p when LSP support is disabled).

I don't think anyone has got LSP working yet under MacOS.

johncbowman commented 1 year ago

As a first step, to compile with --lsp under MacOS, you first need to fix the names of these boost libraries:

ln -s /opt/local/lib/libboost_thread-mt.dylib /opt/local/lib/libboost_thread.dylib ln -s /opt/local/lib/libboost_filesystem-mt.dylib /opt/local/lib/libboost_filesystem.dylib

and then run configure and make again.