mason.nvim icon indicating copy to clipboard operation
mason.nvim copied to clipboard

Can not get LS installation path

Open Naadiyaar opened this issue 7 months ago • 7 comments

I've searched open issues for similar requests

  • [x] Yes

I've recently downloaded the latest plugin version of mason.nvim

  • [x] Yes

Problem description

I'm trying to get path for LS via

local jdtls_install = require('mason-registry')
    .get_package('jdtls')
    :get_install_path()

but that returns an error:

E5108: Error executing lua [string ":lua"]:1: attempt to call method 'get_install_path' (a nil value)                                                                                                       
stack traceback:                                                                                                                                                                                                    
        [string ":lua"]:1: in main chunk

Expected behavior

return absolute path to package.

Steps to reproduce

  1. install mason
  2. install language server
  3. run local jdtls_install = require('mason-registry').get_package('jdtls'):get_install_path()

Neovim version (>= 0.10.0)

tried on both nightly and 0.11.1

Operating system/version

Linux zen 6.14.5-300.fc42.x86_64 #1 SMP PREEMPT_DYNAMIC Fri May 2 14:16:46 UTC 2025 x86_64 GNU/Linux

Healthcheck output

==============================================================================
mason:                                                                    9 ⚠️

mason.nvim ~
- ✅ OK mason.nvim version v2.0.0
- ✅ OK PATH: prepend
- ✅ OK Providers: 
    mason.providers.registry-api
    mason.providers.client
- ✅ OK neovim version >= 0.10.0

mason.nvim [Registries] ~
- ✅ OK Registry `github.com/mason-org/mason-registry version: 2025-05-11-absent-donkey` is installed.

mason.nvim [Core utils] ~
- ✅ OK unzip: `UnZip 6.00 of 20 April 2009, by Info-ZIP.  Maintained by C. Spieler.  Send`
- ✅ OK wget: `GNU Wget2 2.2.0 - multithreaded metalink/file/website downloader`
- ✅ OK curl: `curl 8.11.1 (x86_64-redhat-linux-gnu) libcurl/8.11.1 OpenSSL/3.2.4 zlib/1.3.1.zlib-ng brotli/1.1.0 libidn2/2.3.8 libpsl/0.21.5 libssh/0.11.1/openssl/zlib nghttp2/1.64.0 OpenLDAP/2.6.9`
- ✅ OK gzip: `gzip 1.13`
- ✅ OK gtar: `tar (GNU tar) 1.35`
- ✅ OK bash: `GNU bash, version 5.2.37(1)-release (x86_64-redhat-linux-gnu)`
- ✅ OK sh: `Ok`

mason.nvim [Languages] ~
- ⚠️ WARNING Go: not available
  - ADVICE:
    - spawn: go failed with exit code - and signal -. Could not find executable "go" in PATH.

- ⚠️ WARNING cargo: not available
  - ADVICE:
    - spawn: cargo failed with exit code - and signal -. Could not find executable "cargo" in PATH.

- ⚠️ WARNING luarocks: not available
  - ADVICE:
    - spawn: luarocks failed with exit code - and signal -. Could not find executable "luarocks" in PATH.

- ⚠️ WARNING Ruby: not available
  - ADVICE:
    - spawn: ruby failed with exit code - and signal -. Could not find executable "ruby" in PATH.

- ⚠️ WARNING RubyGem: not available
  - ADVICE:
    - spawn: gem failed with exit code - and signal -. Could not find executable "gem" in PATH.

- ⚠️ WARNING Composer: not available
  - ADVICE:
    - spawn: composer failed with exit code - and signal -. Could not find executable "composer" in PATH.

- ⚠️ WARNING PHP: not available
  - ADVICE:
    - spawn: php failed with exit code - and signal -. Could not find executable "php" in PATH.

- ⚠️ WARNING julia: not available
  - ADVICE:
    - spawn: julia failed with exit code - and signal -. Could not find executable "julia" in PATH.

- ✅ OK python: `Python 3.13.3`
- ✅ OK node: `v22.15.0`
- ✅ OK java: `openjdk version "21.0.7" 2025-04-15 LTS`
- ✅ OK JAVA_HOME: `openjdk version "21.0.7" 2025-04-15 LTS`
- ⚠️ WARNING pip: not available
  - ADVICE:
    - spawn: python3 failed with exit code 1 and signal 0. /usr/bin/python3: No module named pip

- ✅ OK python venv: `Ok`
- ✅ OK javac: `javac 21.0.7`
- ✅ OK npm: `10.9.2`

Screenshots

No response

Naadiyaar avatar May 12 '25 07:05 Naadiyaar

Hey, I just updated my configuration and I have the same issue. Here is the cause: https://github.com/mason-org/mason.nvim/blob/main/CHANGELOG.md#packageget_install_path-has-been-removed

It is not clear to me yet how to deal with it, it seems it broke several plugins on my side

gverger avatar May 12 '25 13:05 gverger

I ran into this myself as well. The changelog gives some recommendations for how to deal with this, and it may depend on how you're using jdtls_install

For me, I was using it to get the lombok jar from jdtls, so I fixed it by changing

     "-javaagent:" .. require("mason-registry")
      .get_package("jdtls")
      :get_install_path() .. "/lombok.jar",

to

    '-javaagent:' .. vim.fn.expand("$MASON/share/jdtls/lombok.jar"),

If you just want the jdtls install directory I believe that would be

vim.fn.expand("$MASON/packages/jdtls/")

(not sure if you'd want the trailing '/') but from the changelog it seems as though that using packages is not recommended.

nickrodgers42 avatar May 12 '25 15:05 nickrodgers42

What if one does not explicitly call any of that, and mason.nvim is just a transient dependency? :(

peterstorm-oi-flex avatar May 13 '25 06:05 peterstorm-oi-flex

get_install_path() seems to be removed. use vim.env.MASON or vim.fn.expand("$MASON") to retrieve mason root

rltyty avatar May 17 '25 04:05 rltyty

get_install_path() and vim.env.MASON serve different purposes. in this case we don't need path to Mason's root, but rather the installation destination of a package.

Naadiyaar avatar May 17 '25 22:05 Naadiyaar

I switched to vim.fn.expand("$MASON"), but, in my jdtls config sometimes this variable did not have a value and I needed to restart nvim until it worked.

Using Lazy, I tried to use mason as a dependency of jdtls to kinda of ensure that mason was loaded before, but it didn't work.

Just adding a simple require "mason" at the top of the jdtls config, this problem stopped.

I'm using the following snippet:

require("mason")

...
local get_package_install_path = function(package_name)
    return vim.fn.expand("$MASON/packages/" .. package_name)
end

local jdtls_path = get_package_install_path('jdtls')

GiuseppeMP avatar Jun 09 '25 11:06 GiuseppeMP

FYI I had the same issue using lazy.nvim, I set lazy = false in my mason plugin spec and it fixed the issue.

I switched to vim.fn.expand("$MASON"), but, in my jdtls config sometimes this variable did not have a value and I needed to restart nvim until it worked.

fpbouchard avatar Aug 03 '25 20:08 fpbouchard