Skip to content

Commit d848936

Browse files
author
Astro
authored
Merge pull request #14 from tobias-z/pr/jdtls-support
Support for Java jdtls
2 parents efe64fa + 20e5888 commit d848936

5 files changed

Lines changed: 49 additions & 5 deletions

File tree

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Dim
2+
23
**dim** is a lua plugin for neovim to dim the unused variables and functions using lsp and treesitter.
34

45
<video src = "https://user-images.githubusercontent.com/79555780/157270883-da3120c8-b8b2-4036-8063-3b5ce10d4d88.mp4"></video>
@@ -50,8 +51,10 @@ Dim comes with the following defaults:
5051
```
5152

5253
## Tested LSPs
54+
5355
| LSPs | Status |
54-
|---------------|--------|
55-
| tsserver | ✔️ |
56-
| sumneko_lua | ✔️ |
57-
| rust_analyzer | ✔️ |
56+
| ------------- | ------ |
57+
| tsserver | ✔️ |
58+
| sumneko_lua | ✔️ |
59+
| rust_analyzer | ✔️ |
60+
| jdtls | ✔️ |

lua/dim/diagnostic_util.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local matchers = require("dim.matchers")
2+
13
local M = {}
24

35
---@param lsp_datum Diagnostic
@@ -11,7 +13,12 @@ end
1113

1214
function M.is_unused_symbol_diagnostic(lsp_datum)
1315
local message = string.lower(get_message_from_lsp_diagnostic(lsp_datum))
14-
return string.match(message, "never read") or string.match(message, "unused")
16+
for _, matcher in ipairs(matchers) do
17+
if string.match(message, matcher) then
18+
return true
19+
end
20+
end
21+
return false
1522
end
1623

1724
return M

lua/dim/matchers.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
return {
2+
"never read", -- tsserver
3+
"unused", -- sumneko_lua rust_analyzer
4+
"536870973", -- jdtls variables
5+
"603979894", -- jdtls private methods
6+
"570425421", -- jdtls private fields
7+
}

tests/diagnostic_util_spec.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ describe("is_unused_symbol_diagnostic", function()
4444
},
4545
expected_result = true,
4646
},
47+
{
48+
description = "detects unused symbols from jdtls diagnostics",
49+
lsp_datum = {
50+
code = "536870973",
51+
},
52+
expected_result = true,
53+
},
54+
{
55+
description = "detects unused private methods from jdtls diagnostics",
56+
lsp_datum = {
57+
code = "603979894",
58+
},
59+
expected_result = true,
60+
},
4761
}
4862

4963
local diagnostic_util = require("dim.diagnostic_util")

tests/unused.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package tests;
2+
3+
/** unused */
4+
class Unused {
5+
6+
private String unusedField = "dsadsa";
7+
8+
private void unusedMethod() {}
9+
10+
public static void main() {
11+
String unusedVariable = "dsadasdas";
12+
}
13+
}

0 commit comments

Comments
 (0)