Giter VIP home page Giter VIP logo

Comments (7)

hooger avatar hooger commented on July 30, 2024 2

Maybe necro bump and not relevant, but I want to document it somewhere. With Kate I also hade some trouble setting up LSPServer, here is how I solved it.

First I ran the provided PacletInstall commands inside Mathematica, that is documented (mostly) clearly and worked without issue. However the documentation felt a bit ambiguous about the version information, as first I thougth it is also only available from 13+ based on the Setup while I was running 12.2. Based on my experience now I understand that from 13+ you don't have to run PacletInstall and it is needed (but works!) on earlier versions.

What I needed next was a command that Kate can run to fire up the server, however the oneliner with arguments did not work, so I created a script file (under Linux it was a bash script, but I think bat file under Windows, or the equivalent under Mac works the same) that contains the following:

#! /bin/bash

WolframKernel -noinit -noprompt -nopaclet -noicon -nostartuppaclets -run 'Needs["LSPServer`"];LSPServer`StartServer[]'

and provided the script to the lspclient. The oneliner does not look the same as in the "Using LSPServer" section in the readme. I copied it from the sublime extensions source code, here: https://github.com/WolframResearch/Sublime-WolframLanguage/blob/master/WolframLanguage.sublime-settings#L21-L36 I'm not sure why it differs from the readme.

If I may suggest, please update the 'Using LSPServer" section of the Readme with some hints around the used arguments and that it is not just a test, however this should be given also to the lspclient. It may be evident to someone with knowledge around the protocol, but it took me a couple of hours to figure out.

Also, to leave a positive comment as well, I really like the fact that Wolfram Mathematica contains everything essential to be used even without the notebook frontend. 🎉

from lspserver.

bostick avatar bostick commented on July 30, 2024

The LSPServer package provides a Wolfram Language LSP server for any LSP client, so if your vim or neovim has LSP client support, then it should definitely work just fine.

What have you tried so far?

from lspserver.

bostick avatar bostick commented on July 30, 2024

Thank you for the feedback.

A possible source of confusion about versions may be about the specific versions that appear in the paths for WolframKernel. When talking about the full path to WolframKernel on your machine, I like to give the default location for the latest version, so for example on Windows, it would be:
C:\Program Files\Wolfram Research\Wolfram Engine\13.1\WolframKernel.exe

And this will be updated when 13.2 is released.

But this in no way implies that 13.1 is required. In fact, if you built from sources, you would be to go back to using version 12.1.

I'd like to understand any suggestion for better documentation around version information.

I will work to update the "Using LSPServer" section to be more clear.

Thanks again!

from lspserver.

even4void avatar even4void commented on July 30, 2024

I can confirm that @hooger's solution works in Neovim (nightly). Here is part of my config that shows how to setup Wolfram Language Server:

local configs = require("lspconfig.configs")
configs.lsp_wl = {
  default_config = {
    cmd = {
      "wolfram",
      "kernel",
      "-noinit",
      "-noprompt",
      "-nopaclet",
      "-noicon",
      "-nostartuppaclets",
      "-run",
      'Needs["LSPServer`"];LSPServer`StartServer[]',
    },
    filetypes = { "mma" },
    root_dir = nvim_lsp.util.path.dirname,
    autostart = false,
  },
}
nvim_lsp.lsp_wl.setup({
  on_attach = function(client, bufnr)
    vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.MiniCompletion.completefunc_lsp")
    vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
    vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
    vim.keymap.set("n", "<leader>wd", vim.diagnostic.open_float)
    vim.keymap.set("n", "<leader>ww", vim.diagnostic.setqflist)
    vim.keymap.set("i", "<C-h>", vim.lsp.buf.signature_help, opts)
    vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
    vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
    vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
    vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
    vim.keymap.set("n", "gI", vim.lsp.buf.type_definition, opts)
    vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
    vim.keymap.set("n", "z=", vim.lsp.buf.code_action, opts)
    vim.keymap.set("n", "zr", vim.lsp.buf.rename, opts)
  end,
})

Note that:

  1. I use the old mma filetype, even for wls scripts.
  2. With these settings, you will need to start the server manually (or set autostart = true).
  3. You can enable autoformatting on save in on_attach in addition to LSP mappings, or use a custom mapping in your ftplugin directory, e.g.:
nmap <buffer> <silent> g= :lua vim.lsp.buf.format()<cr>

from lspserver.

JuanG970 avatar JuanG970 commented on July 30, 2024

Hello @even4void I am having some problems connecting Wolfram LSP and neovim, could you provide some more details about your config file? It should be placed under init.vim ?

Do you think it is possible to provide wolfram language support using COC ?

from lspserver.

even4void avatar even4void commented on July 30, 2024

could you provide some more details about your config file? It should be placed under init.vim ?

I put everything related to LSP in a dedicated file (http://ix.io/4rAH), then require it from my init fiile (http://ix.io/4rAI), or rather a separate file (http://ix.io/4rAJ) where I manage plugins. I don't know about your config, but the above config is tied to a proper setup of nvim-lspconfig. I don't use COC so I can't tell if these settings apply in this case (probably not, since COC uses its own setup).

from lspserver.

JuanG970 avatar JuanG970 commented on July 30, 2024

I have this working using the following settings inside my init.vim file:

lua << EOF
local autocmd = vim.api.nvim_create_autocmd
autocmd("FileType", {
    pattern = "mma",
    callback = function()
        local root_dir = vim.fs.dirname(
            vim.fs.find({ '.git' }, { upward = true })[1]
        )

        local client = vim.lsp.start({
            name = 'wolfram-lsp',
            cmd = {
                "/Applications/Mathematica.app/Contents/MacOS/WolframKernel",
                "kernel",
                "-noinit",
                "-noprompt",
                "-nopaclet",
                "-noicon",
                "-nostartuppaclets",
                "-run",
                'Needs["LSPServer`"];LSPServer`StartServer[]',
            },
            root_dir = root_dir
        })


        vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
        vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
        vim.keymap.set("n", "<leader>kd", vim.diagnostic.open_float)
        vim.keymap.set("n", "<leader>kw", vim.diagnostic.setqflist)
        vim.keymap.set("i", "<C-h>", vim.lsp.buf.signature_help)
        vim.keymap.set("n", "K", vim.lsp.buf.hover)
        vim.keymap.set("n", "gr", vim.lsp.buf.references)
        -- This requires Telescope to be installed.
        vim.keymap.set("n", "<leader>d", ":Telescope lsp_document_symbols<CR>", { noremap = true, silent = true })

        -- This line is optional
        print('Key bindings defined')

        vim.lsp.buf_attach_client(0, client)

    end
})
EOF

Essentially, starts the LSP each time a mathematica file is opened.

from lspserver.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.