Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ globals = {
'vim.wo',
'vim.bo',
'vim.opt',
'vim.lsp',
}
read_globals = {
'vim',
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ Yep! That's all :)

- `JavaRefactorExtractVariable` - Create a variable from returned value at cursor

### Settings

- `JavaSettingsChangeRuntime` - Change the JDK version to another

</details>

## :computer: APIs
Expand Down Expand Up @@ -214,6 +218,14 @@ require('java').profile.ui()
require('java').refactor.extract_variable()
```

### Settings

- `change_runtime` - Change the JDK version to another

```lua
require('java').settings.change_runtime()
```

</details>

## :clamp: How to Use JDK X.X Version?
Expand Down
21 changes: 21 additions & 0 deletions lua/java.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('java.commands')

local decomple_watch = require('java.startup.decompile-watcher')
local mason_dep = require('java.startup.mason-dep')
local setup_wrap = require('java.startup.lspconfig-setup-wrap')
Expand All @@ -9,17 +11,25 @@ local runner = require('java.api.runner')
local profile_ui = require('java.ui.profile')
local refactor = require('java.api.refactor')
local build_api = require('java.api.build')
local settings_api = require('java.api.settings')

local global_config = require('java.config')

local M = {}

function M.setup(custom_config)
vim.api.nvim_exec_autocmds('User', { pattern = 'JavaPreSetup' })

local config =
vim.tbl_deep_extend('force', global_config, custom_config or {})

vim.g.nvim_java_config = config

vim.api.nvim_exec_autocmds(
'User',
{ pattern = 'JavaSetup', data = { config = config } }
)

if not startup_check() then
return
end
Expand All @@ -31,6 +41,11 @@ function M.setup(custom_config)
decomple_watch.setup()
dap.setup_dap_on_lsp_attach()
end

vim.api.nvim_exec_autocmds(
'User',
{ pattern = 'JavaPostSetup', data = { config = config } }
)
end

----------------------------------------------------------------------
Expand Down Expand Up @@ -86,6 +101,12 @@ M.runner.built_in.switch_app = runner.built_in.switch_app
M.profile = {}
M.profile.ui = profile_ui.ui

----------------------------------------------------------------------
-- Settings --
----------------------------------------------------------------------
M.settings = {}
M.settings.change_runtime = settings_api.change_runtime

function M.__run()
test.debug_current_method()
end
Expand Down
23 changes: 15 additions & 8 deletions lua/java/api/build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@ local get_error_handler = require('java.handlers.error')

local M = {}

function M.full_build_workspace()
return async(function()
local JavaCoreJdtlsClient = require('java-core.ls.clients.jdtls-client')
local jdtls = require('java.utils.jdtls')
local buf_util = require('java.utils.buffer')
local notify = require('java-core.utils.notify')
---Do a workspace build
---@param is_full_build? boolean
---@return number
function M.full_build_workspace(is_full_build)
local JavaCoreJdtlsClient = require('java-core.ls.clients.jdtls-client')
local jdtls = require('java.utils.jdtls2')
local buf_util = require('java.utils.buffer')
local notify = require('java-core.utils.notify')

is_full_build = type(is_full_build) == 'boolean' and is_full_build or true

JavaCoreJdtlsClient:new(jdtls())
:java_build_workspace(true, buf_util.get_curr_buf())
return async(function()
JavaCoreJdtlsClient(jdtls()):java_build_workspace(
is_full_build,
buf_util.get_curr_buf()
)

notify.info('Workspace build successful!')
end)
Expand Down
57 changes: 57 additions & 0 deletions lua/java/api/settings.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
local get_jdtls = require('java.utils.jdtls2')
local JdtlsClient = require('java-core.ls.clients.jdtls-client')
local conf_utils = require('java.utils.config')
local notify = require('java-core.utils.notify')
local ui = require('java.utils.ui')
local async = require('java-core.utils.async').sync
local get_error_handler = require('java.handlers.error')

local M = {}

function M.change_runtime()
local client = get_jdtls()

---@type RuntimeOption[]
local runtimes = conf_utils.get_property_from_conf(
client.config,
'settings.java.configuration.runtimes',
{}
)

if #runtimes < 1 then
notify.error(
'No configured runtimes available'
.. '\nRefer following link for instructions define available runtimes'
.. '\nhttps://github.com/nvim-java/nvim-java?tab=readme-ov-file#clamp-how-to-use-jdk-xx-version'
)
return
end

local jdtls = JdtlsClient(client)

async(function()
local sel_runtime = ui.select(
'Select Runtime',
runtimes,
function(runtime)
return runtime.name .. '::' .. runtime.path
end
)

for _, runtime in
ipairs(client.config.settings.java.configuration.runtimes)
do
if sel_runtime.path == runtime.path then
runtime.default = true
else
runtime.default = nil
end
end

jdtls:workspace_did_change_configuration(client.config.settings)
end)
.catch(get_error_handler('Changing runtime failed'))
.run()
end

return M
200 changes: 200 additions & 0 deletions lua/java/commands/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
local log = require('java.utils.log')

local M = {}

local id

id = vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)

if client and client.name == 'jdtls' then
log.debug('adding vim.lsp.commands for java')

for key, handler in pairs(M.handlers) do
vim.lsp.commands[key] = handler
end

vim.api.nvim_del_autocmd(id)
end
end,

group = vim.api.nvim_create_augroup('JavaCommandReg', {}),
})

M.commands = {

OPEN_BROWSER = 'vscode.open',

OPEN_OUTPUT = 'java.open.output',

SHOW_JAVA_REFERENCES = 'java.show.references',

SHOW_JAVA_IMPLEMENTATIONS = 'java.show.implementations',

SHOW_REFERENCES = 'editor.action.showReferences',

GOTO_LOCATION = 'editor.action.goToLocations',

MARKDOWN_API_RENDER = 'markdown.api.render',

CONFIGURATION_UPDATE = 'java.projectConfiguration.update',

IGNORE_INCOMPLETE_CLASSPATH = 'java.ignoreIncompleteClasspath',

IGNORE_INCOMPLETE_CLASSPATH_HELP = 'java.ignoreIncompleteClasspath.help',

RELOAD_WINDOW = 'workbench.action.reloadWindow',

PROJECT_CONFIGURATION_STATUS = 'java.projectConfiguration.status',

NULL_ANALYSIS_SET_MODE = 'java.compile.nullAnalysis.setMode',

APPLY_WORKSPACE_EDIT = 'java.apply.workspaceEdit',

EXECUTE_WORKSPACE_COMMAND = 'java.execute.workspaceCommand',

COMPILE_WORKSPACE = 'java.workspace.compile',

BUILD_PROJECT = 'java.project.build',

OPEN_SERVER_LOG = 'java.open.serverLog',

OPEN_SERVER_STDOUT_LOG = 'java.open.serverStdoutLog',

OPEN_SERVER_STDERR_LOG = 'java.open.serverStderrLog',

OPEN_CLIENT_LOG = 'java.open.clientLog',

OPEN_LOGS = 'java.open.logs',

OPEN_FORMATTER = 'java.open.formatter.settings',

OPEN_FILE = 'java.open.file',

CLEAN_WORKSPACE = 'java.clean.workspace',

UPDATE_SOURCE_ATTACHMENT_CMD = 'java.project.updateSourceAttachment.command',
UPDATE_SOURCE_ATTACHMENT = 'java.project.updateSourceAttachment',

RESOLVE_SOURCE_ATTACHMENT = 'java.project.resolveSourceAttachment',

ADD_TO_SOURCEPATH_CMD = 'java.project.addToSourcePath.command',
ADD_TO_SOURCEPATH = 'java.project.addToSourcePath',

REMOVE_FROM_SOURCEPATH_CMD = 'java.project.removeFromSourcePath.command',
REMOVE_FROM_SOURCEPATH = 'java.project.removeFromSourcePath',

LIST_SOURCEPATHS_CMD = 'java.project.listSourcePaths.command',
LIST_SOURCEPATHS = 'java.project.listSourcePaths',

IMPORT_PROJECTS_CMD = 'java.project.import.command',
IMPORT_PROJECTS = 'java.project.import',
CHANGE_IMPORTED_PROJECTS = 'java.project.changeImportedProjects',

OVERRIDE_METHODS_PROMPT = 'java.action.overrideMethodsPrompt',

HASHCODE_EQUALS_PROMPT = 'java.action.hashCodeEqualsPrompt',

OPEN_JSON_SETTINGS = 'workbench.action.openSettingsJson',

ORGANIZE_IMPORTS = 'java.action.organizeImports',

ORGANIZE_IMPORTS_SILENTLY = 'java.edit.organizeImports',
MANUAL_CLEANUP = 'java.action.doCleanup',

HANDLE_PASTE_EVENT = 'java.edit.handlePasteEvent',

CLIPBOARD_ONPASTE = 'java.action.clipboardPasteAction',

FILESEXPLORER_ONPASTE = 'java.action.filesExplorerPasteAction',

CHOOSE_IMPORTS = 'java.action.organizeImports.chooseImports',

GENERATE_TOSTRING_PROMPT = 'java.action.generateToStringPrompt',

GENERATE_ACCESSORS_PROMPT = 'java.action.generateAccessorsPrompt',

GENERATE_CONSTRUCTORS_PROMPT = 'java.action.generateConstructorsPrompt',

GENERATE_DELEGATE_METHODS_PROMPT = 'java.action.generateDelegateMethodsPrompt',

APPLY_REFACTORING_COMMAND = 'java.action.applyRefactoringCommand',

RENAME_COMMAND = 'java.action.rename',

NAVIGATE_TO_SUPER_IMPLEMENTATION_COMMAND = 'java.action.navigateToSuperImplementation',

SHOW_TYPE_HIERARCHY = 'java.action.showTypeHierarchy',

SHOW_SUPERTYPE_HIERARCHY = 'java.action.showSupertypeHierarchy',

SHOW_SUBTYPE_HIERARCHY = 'java.action.showSubtypeHierarchy',

SHOW_CLASS_HIERARCHY = 'java.action.showClassHierarchy',

CHANGE_BASE_TYPE = 'java.action.changeBaseType',

OPEN_TYPE_HIERARCHY = 'java.navigate.openTypeHierarchy',

RESOLVE_TYPE_HIERARCHY = 'java.navigate.resolveTypeHierarchy',

SHOW_SERVER_TASK_STATUS = 'java.show.server.task.status',

GET_PROJECT_SETTINGS = 'java.project.getSettings',

GET_CLASSPATHS = 'java.project.getClasspaths',

IS_TEST_FILE = 'java.project.isTestFile',

GET_ALL_JAVA_PROJECTS = 'java.project.getAll',

SWITCH_SERVER_MODE = 'java.server.mode.switch',

RESTART_LANGUAGE_SERVER = 'java.server.restart',

LEARN_MORE_ABOUT_REFACTORING = '_java.learnMoreAboutRefactorings',

LEARN_MORE_ABOUT_CLEAN_UPS = '_java.learnMoreAboutCleanUps',

TEMPLATE_VARIABLES = '_java.templateVariables',

NOT_COVERED_EXECUTION = '_java.notCoveredExecution',

METADATA_FILES_GENERATION = '_java.metadataFilesGeneration',

RUNTIME_VALIDATION_OPEN = 'java.runtimeValidation.open',

RESOLVE_WORKSPACE_SYMBOL = 'java.project.resolveWorkspaceSymbol',

GET_WORKSPACE_PATH = '_java.workspace.path',

UPGRADE_GRADLE_WRAPPER_CMD = 'java.project.upgradeGradle.command',
UPGRADE_GRADLE_WRAPPER = 'java.project.upgradeGradle',

LOMBOK_CONFIGURE = 'java.lombokConfigure',

CREATE_MODULE_INFO = 'java.project.createModuleInfo',

CREATE_MODULE_INFO_COMMAND = 'java.project.createModuleInfo.command',

REFRESH_BUNDLES = 'java.reloadBundles',

REFRESH_BUNDLES_COMMAND = '_java.reloadBundles.command',

CLEAN_SHARED_INDEXES = 'java.clean.sharedIndexes',

GET_DECOMPILED_SOURCE = 'java.decompile',

SMARTSEMICOLON_DETECTION = 'java.edit.smartSemicolonDetection',

RESOLVE_PASTED_TEXT = 'java.project.resolveText',

OPEN_STATUS_SHORTCUT = '_java.openShortcuts',
}

M.handlers = {
[M.commands.COMPILE_WORKSPACE] = function(is_full_build)
require('java.api.build').full_build_workspace(is_full_build)
end,
}
Loading