Skip to content

fix: update mason API usage for nvim-java compatibility #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Kabil777
Copy link

@Kabil777 Kabil777 commented May 8, 2025

Summary

This PR updates deprecated Mason APIs (get_install_path) used in nvim-java-core to work with Mason v2.2.0+.

Changes

  • Updated: init.lua in ls/servers/jdtls to use vim.fn.expand("$MASON/…") for finding JDK paths.
  • Updated: utils/mason.lua to replace deprecated Mason API calls with standard path functions (vim.fn.stdpath).
  • Handled: safe usage of get_package with pcall to avoid crashes when packages are not installed.

Motivation

Recent versions of mason.nvim removed or changed the get_install_path() method, breaking integration with nvim-java. This patch restores compatibility.

Testing

Tested with:

  • Mason v2.2.0

@Coding4Hours

This comment was marked as abuse.

@Coding4Hours

This comment was marked as abuse.

@Coding4Hours

This comment was marked as abuse.

@gierdo
Copy link

gierdo commented May 11, 2025

this error is so stupid and i need java because im training for usaco

You can install mason in version 1.x, or alternatively use nvim-java-compatibility from Kabil777's fork.

How you can do that depends on you plugin manager and your configuration, though. So it's a bit hard to guide you.

With lazy, e.g., you can do

  {
    "williamboman/mason.nvim",
    branch = "v1.x",
...

Or you can apply the fix proposed here:

LazyVim/LazyVim#6053 (comment)

Or you can do this:

  {
    "nvim-java/nvim-java",
...
    dependencies = {
      {
        "nvim-java/nvim-java-core",
        url = "https://github.com/Kabil777/nvim-java-core.git",
        branch = "fix/mason-api-update",
      },
    },
  },

@Coding4Hours

This comment was marked as abuse.

@Zeioth
Copy link

Zeioth commented May 11, 2025

@s1n7ax merging this PR is also necessary.

@s1n7ax
Copy link
Member

s1n7ax commented May 12, 2025

this error is so stupid and i need java because im training for usaco

@Coding4Hours I don't give a shit wtf you are training for. Don't know how branches work? Then stop trying you will be replaced by AI in few months anyway

@@ -6,21 +6,25 @@ local M = {}
---@param pkg_name string
---@return string | nil
function M.get_pkg_path(pkg_name)
return mason_registry.get_package(pkg_name):get_install_path()
local mason_data_path = vim.fn.stdpath("data") .. "/mason/packages/" .. pkg_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In prev you used $MASON variable but here get stdpath?

function M.get_shared_path(pkg_name)
return vim.fn.glob('$MASON/share/' .. pkg_name)
local mason_share_path = vim.fn.stdpath("data") .. "/mason/share/" .. pkg_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use $MASON env variable?

@s1n7ax
Copy link
Member

s1n7ax commented May 12, 2025

Release notes states that the way to get the path is using $MASON environment variable. You could fix all occurrences to use $MASON or I fix and merge in few days. Formatting has to be fixed as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants