Skip to content

Commit 9322f1a

Browse files
committed
docs: restructure README and add English translation
1 parent 2ec5d2f commit 9322f1a

2 files changed

Lines changed: 158 additions & 87 deletions

File tree

‎README.md‎

Lines changed: 62 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,27 @@
11
# Java Projects
22

3-
## 安装
3+
简体中文 | [English](README_EN.md)
4+
5+
在 Neovim 中以树形视图浏览 Java 项目、包和依赖,数据来自 [vscode-java-dependency](https://github.com/Microsoft/vscode-java-dependency)。
6+
7+
![Java Projects](https://github.com/JavaHello/javahello.github.io/raw/refs/heads/master/static/nvim/nvim-java-deps-new.png)
48

5-
[English](https://github.com/JavaHello/java-deps.nvim/issues/2)
9+
## 安装
610

7-
- lazy.nvim
11+
使用 [lazy.nvim](https://github.com/folke/lazy.nvim):
812

913
```lua
1014
{
11-
"JavaHello/java-deps.nvim",
12-
lazy = true,
13-
ft = "java",
14-
dependencies = "mfussenegger/nvim-jdtls",
15-
config = function()
16-
require("java-deps").setup({
17-
symbols = {
18-
icons = {
19-
NodeKind = {
20-
-- project 节点改成文件夹图标
21-
Project = "󰉋",
22-
-- 也支持同时覆盖 icon 和高亮
23-
Workspace = { icon = "󱁐", hl = "Directory" },
24-
},
25-
TypeKind = {
26-
Class = "󰌗",
27-
Interface = { icon = "", hl = "Function" },
28-
},
29-
},
30-
highlights = {
31-
default_icon = "Identifier",
32-
NodeKind = {
33-
File = "Directory",
34-
Package = "Directory",
35-
},
36-
},
37-
},
38-
highlights = {
39-
LineGuide = { link = "Comment" },
40-
},
41-
})
42-
end,
43-
}
44-
15+
"JavaHello/java-deps.nvim",
16+
ft = "java",
17+
dependencies = "mfussenegger/nvim-jdtls",
18+
opts = {},
19+
}
4520
```
4621

47-
可配置项说明:
22+
### 配置 jdtls
4823

49-
- `symbols.icons.<分类>.<枚举名>`: 覆盖图标,值可以是字符串,或者 `{ icon = "...", hl = "..." }`
50-
- `symbols.highlights.default_icon`: 图标没有高亮组时使用的兜底高亮组(内置默认图标都已自带高亮组)
51-
- `symbols.highlights.<分类>.<枚举名>`: 仅覆盖某个图标的高亮组
52-
- `highlights.LineGuide`: 定义 `JavaDepsLineGuide` 高亮组
53-
- `hierarchical_view`: 包是否按层级展示,默认 `true`(`com.example.a` 显示为 `com.example` → `a`),设为 `false` 时平铺显示完整包名
54-
- `show_non_java_resources`: 是否显示非 java 资源(如 `src/main/resources` 下的配置文件),默认 `true`
55-
56-
目前支持的分类:
57-
58-
- `symbols.icons.NodeKind`: `Workspace` `Project` `PackageRoot` `Package` `PrimaryType` `CompilationUnit` `ClassFile` `Container` `Folder` `File`
59-
- `symbols.icons.TypeKind`: `Class` `Interface` `Enum`
60-
- `symbols.icons.EntryKind`: `K_SOURCE`(源码目录)`K_BINARY`(jar 包)
61-
- `symbols.icons.ProjectKind`: `MavenParent`(没有 java nature 的 Maven 父工程)`Maven` `GradleRoot`(没有 java nature 的 Gradle 根工程)`Gradle` `UnmanagedFolder` `Java`,按项目类型区分 Project 节点
62-
- `symbols.icons.ContainerKind`: `JRE` `Maven` `Gradle` `ReferencedLibrary`,按依赖容器类型区分 Container 节点
63-
64-
`ProjectKind` / `ContainerKind` / `EntryKind` / `TypeKind` 未匹配时回退到 `NodeKind` 中对应的图标。
65-
66-
- 手动编译 `vscode-java-dependency` (可选)
24+
1. 编译 `vscode-java-dependency`:
6725

6826
```sh
6927
git clone https://github.com/microsoft/vscode-java-dependency.git
@@ -72,50 +30,67 @@ npm install
7230
npm run build-server
7331
```
7432

75-
- 将 `vscode-java-dependency` 的 `jar` 包添加到 jdtls_config["init_options"].bundles 中
33+
2. 将生成的 jar 包加入 jdtls 的 `bundles`,并注册命令:
7634

7735
```lua
78-
local jdtls_config = {}
7936
local bundles = {}
80-
-- ...
81-
local java_dependency_bundle = vim.split(
82-
vim.fn.glob(
83-
"/path?/vscode-java-dependency/jdtls.ext/com.microsoft.jdtls.ext.core/target/com.microsoft.jdtls.ext.core-*.jar"
84-
),
85-
"\n"
86-
)
87-
88-
if java_dependency_bundle[1] ~= "" then
89-
vim.list_extend(bundles, java_dependency_bundle)
90-
end
37+
vim.list_extend(bundles, vim.split(vim.fn.glob(
38+
"/path/to/vscode-java-dependency/jdtls.ext/com.microsoft.jdtls.ext.core/target/com.microsoft.jdtls.ext.core-*.jar"
39+
), "\n", { trimempty = true }))
9140

92-
jdtls_config["init_options"] = {
93-
bundles = bundles,
94-
extendedClientCapabilities = extendedClientCapabilities,
95-
}
96-
```
97-
98-
- 添加命令
41+
jdtls_config.init_options = { bundles = bundles }
9942

100-
```lua
101-
jdtls_config["on_attach"] = function(client, buffer)
102-
-- 添加命令
103-
local create_command = vim.api.nvim_buf_create_user_command
104-
create_command(buffer, "JavaProjects", require("java-deps").toggle_outline, {
105-
nargs = 0,
106-
})
43+
jdtls_config.on_attach = function(client, buffer)
44+
vim.api.nvim_buf_create_user_command(buffer, "JavaProjects", require("java-deps").toggle_outline, { nargs = 0 })
10745
end
10846
```
10947

110-
- Usage
48+
## 使用
11149

11250
```vim
11351
:lua require('java-deps').toggle_outline()
11452
:lua require('java-deps').open_outline()
11553
:lua require('java-deps').close_outline()
11654
```
11755

118-
## 参考实现
56+
## 配置
57+
58+
```lua
59+
require("java-deps").setup({
60+
hierarchical_view = true, -- 包按层级展示;false 时平铺完整包名
61+
show_non_java_resources = true, -- 显示非 java 资源(如 src/main/resources)
62+
symbols = {
63+
icons = {
64+
NodeKind = {
65+
Project = "󰉋",
66+
Workspace = { icon = "󱁐", hl = "Directory" }, -- 同时覆盖图标和高亮
67+
},
68+
TypeKind = { Class = "󰌗" },
69+
},
70+
highlights = {
71+
default_icon = "Identifier", -- 图标无高亮组时的兜底
72+
NodeKind = { Package = "Directory" }, -- 仅覆盖高亮组
73+
},
74+
},
75+
highlights = {
76+
LineGuide = { link = "Comment" }, -- JavaDepsLineGuide 高亮组
77+
},
78+
})
79+
```
80+
81+
图标分类(`symbols.icons.<分类>.<名称>` / `symbols.highlights.<分类>.<名称>`):
82+
83+
| 分类 | 名称 |
84+
| --- | --- |
85+
| `NodeKind` | `Workspace` `Project` `PackageRoot` `Package` `PrimaryType` `CompilationUnit` `ClassFile` `Container` `Folder` `File` |
86+
| `TypeKind` | `Class` `Interface` `Enum` |
87+
| `EntryKind` | `K_SOURCE`(源码目录)`K_BINARY`(jar 包) |
88+
| `ProjectKind` | `MavenParent` `Maven` `GradleRoot` `Gradle` `UnmanagedFolder` `Java` |
89+
| `ContainerKind` | `JRE` `Maven` `Gradle` `ReferencedLibrary` |
90+
91+
`TypeKind` / `EntryKind` / `ProjectKind` / `ContainerKind` 未匹配时回退到 `NodeKind` 中对应的图标。
92+
93+
## 致谢
11994

120-
- 使用 [symbols-outline](https://github.com/simrat39/symbols-outline.nvim) 代码实现预览
121-
- [vscode-java-dependency](https://github.com/Microsoft/vscode-java-dependency) 提供数据支持
95+
- [symbols-outline.nvim](https://github.com/simrat39/symbols-outline.nvim):视图实现参考
96+
- [vscode-java-dependency](https://github.com/Microsoft/vscode-java-dependency):数据支持

‎README_EN.md‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Java Projects
2+
3+
[简体中文](README.md) | English
4+
5+
Browse Java projects, packages and dependencies in a tree view inside Neovim, powered by [vscode-java-dependency](https://github.com/Microsoft/vscode-java-dependency).
6+
7+
![Java Projects](https://github.com/JavaHello/javahello.github.io/raw/refs/heads/master/static/nvim/nvim-java-deps-new.png)
8+
9+
## Installation
10+
11+
With [lazy.nvim](https://github.com/folke/lazy.nvim):
12+
13+
```lua
14+
{
15+
"JavaHello/java-deps.nvim",
16+
ft = "java",
17+
dependencies = "mfussenegger/nvim-jdtls",
18+
opts = {},
19+
}
20+
```
21+
22+
### Set up jdtls
23+
24+
1. Build `vscode-java-dependency`:
25+
26+
```sh
27+
git clone https://github.com/microsoft/vscode-java-dependency.git
28+
cd vscode-java-dependency
29+
npm install
30+
npm run build-server
31+
```
32+
33+
2. Add the built jar to the jdtls `bundles` and register a command:
34+
35+
```lua
36+
local bundles = {}
37+
vim.list_extend(bundles, vim.split(vim.fn.glob(
38+
"/path/to/vscode-java-dependency/jdtls.ext/com.microsoft.jdtls.ext.core/target/com.microsoft.jdtls.ext.core-*.jar"
39+
), "\n", { trimempty = true }))
40+
41+
jdtls_config.init_options = { bundles = bundles }
42+
43+
jdtls_config.on_attach = function(client, buffer)
44+
vim.api.nvim_buf_create_user_command(buffer, "JavaProjects", require("java-deps").toggle_outline, { nargs = 0 })
45+
end
46+
```
47+
48+
## Usage
49+
50+
```vim
51+
:lua require('java-deps').toggle_outline()
52+
:lua require('java-deps').open_outline()
53+
:lua require('java-deps').close_outline()
54+
```
55+
56+
## Configuration
57+
58+
```lua
59+
require("java-deps").setup({
60+
hierarchical_view = true, -- show packages hierarchically; false shows flat full package names
61+
show_non_java_resources = true, -- show non-Java resources (e.g. src/main/resources)
62+
symbols = {
63+
icons = {
64+
NodeKind = {
65+
Project = "󰉋",
66+
Workspace = { icon = "󱁐", hl = "Directory" }, -- override icon and highlight together
67+
},
68+
TypeKind = { Class = "󰌗" },
69+
},
70+
highlights = {
71+
default_icon = "Identifier", -- fallback for icons without a highlight group
72+
NodeKind = { Package = "Directory" }, -- override only the highlight group
73+
},
74+
},
75+
highlights = {
76+
LineGuide = { link = "Comment" }, -- JavaDepsLineGuide highlight group
77+
},
78+
})
79+
```
80+
81+
Icon categories (`symbols.icons.<Category>.<Name>` / `symbols.highlights.<Category>.<Name>`):
82+
83+
| Category | Names |
84+
| --- | --- |
85+
| `NodeKind` | `Workspace` `Project` `PackageRoot` `Package` `PrimaryType` `CompilationUnit` `ClassFile` `Container` `Folder` `File` |
86+
| `TypeKind` | `Class` `Interface` `Enum` |
87+
| `EntryKind` | `K_SOURCE` (source folder) `K_BINARY` (jar) |
88+
| `ProjectKind` | `MavenParent` `Maven` `GradleRoot` `Gradle` `UnmanagedFolder` `Java` |
89+
| `ContainerKind` | `JRE` `Maven` `Gradle` `ReferencedLibrary` |
90+
91+
When `TypeKind` / `EntryKind` / `ProjectKind` / `ContainerKind` has no match, the corresponding `NodeKind` icon is used.
92+
93+
## Credits
94+
95+
- [symbols-outline.nvim](https://github.com/simrat39/symbols-outline.nvim): view implementation reference
96+
- [vscode-java-dependency](https://github.com/Microsoft/vscode-java-dependency): data provider

0 commit comments

Comments
 (0)