|
1 | | -<div align="center"> |
2 | | - <p><h1>simple-completion-language-server</h1> </p> |
3 | | - <p><strong>Allow to use common word completion and snippets for <a href="https://helix-editor.com/">Helix editor</a></strong></p> |
4 | | - <p></p> |
5 | | -</div> |
| 1 | +# scls |
6 | 2 |
|
| 3 | +Fork by https://github.com/estin/simple-completion-language-server |
7 | 4 |
|
8 | | -https://github.com/estin/simple-completion-language-server/assets/520814/10566ad4-d6d1-475b-8561-2e909be0f875 |
| 5 | +具体改动请参考 https://github.com/d1y/scls/pull/6 该 PR |
9 | 6 |
|
10 | | -Based on [comment](https://github.com/helix-editor/helix/pull/3328#issuecomment-1559031060) |
11 | 7 |
|
12 | | -### Install (from source only) |
| 8 | +| 路径提示 | 代码片段 | |
| 9 | +| ----------- | ----------- | |
| 10 | +| <img width="645" alt="image" src="https://github.com/d1y/scls/assets/45585937/a7c3211f-7fa8-4eac-9fe8-23d4943b25e3"> | <img width="780" alt="image" src="https://github.com/d1y/scls/assets/45585937/e02bc64f-4922-40c3-b040-fd643e871786"> | |
| 11 | + |
| 12 | +### Install |
| 13 | + |
| 14 | +TODO: 支持 `brew install` |
13 | 15 |
|
14 | 16 | From GitHub: |
15 | 17 |
|
16 | 18 | ```console |
17 | | -$ cargo install --git https://github.com/estin/simple-completion-language-server.git |
| 19 | +$ cargo install --git https://github.com/d1y/scls |
18 | 20 | ``` |
19 | 21 |
|
20 | 22 | From local repository: |
21 | 23 |
|
22 | 24 | ```console |
23 | | -$ git clone https://github.com/estin/simple-completion-language-server.git |
24 | | -$ cd simple-completion-language-server |
| 25 | +$ git clone https://github.com/d1y/scls |
| 26 | +$ cd scls |
25 | 27 | $ cargo install --path . |
26 | 28 | ``` |
27 | 29 |
|
28 | 30 | ### Configure |
29 | 31 |
|
30 | | -For Helix on `~/.config/helix/languages.toml` |
31 | | - |
32 | | -```toml |
33 | | -# introduce new language server |
34 | | -[language-server.scls] |
35 | | -command = "simple-completion-language-server" |
36 | | - |
37 | | -[language-server.scls.config] |
38 | | -max_completion_items = 20 # set max completion results len for each group: words, snippets, unicode-input |
39 | | -snippets_first = true # completions will return before snippets by default |
40 | | -feature_words = true # enable completion by word |
41 | | -feature_snippets = true # enable snippets |
42 | | -feature_unicode_input = true # enable "unicode input" |
43 | | -feature_paths = true # enable path completion |
44 | | - |
45 | | - |
46 | | -# write logs to /tmp/completion.log |
47 | | -[language-server.scls.environment] |
48 | | -RUST_LOG = "info,simple-completion-langauge-server=info" |
49 | | -LOG_FILE = "/tmp/completion.log" |
50 | | - |
51 | | -# append langage server to existed languages |
52 | | -[[language]] |
53 | | -name = "rust" |
54 | | -language-servers = [ "scls", "rust-analyzer" ] |
55 | | - |
56 | | -[[language]] |
57 | | -name = "git-commit" |
58 | | -language-servers = [ "scls" ] |
59 | | - |
60 | | -# etc.. |
61 | | - |
62 | | -# introduce a new language to enable completion on any doc by forcing set language with :set-language stub |
63 | | -[[language]] |
64 | | -name = "stub" |
65 | | -scope = "text.stub" |
66 | | -file-types = [] |
67 | | -shebangs = [] |
68 | | -roots = [] |
69 | | -auto-format = false |
70 | | -language-servers = [ "scls" ] |
| 32 | +zed-editor: |
| 33 | + |
| 34 | +```jsonc |
| 35 | +"lsp": { |
| 36 | + "scls": { |
| 37 | + "initialization_options": { |
| 38 | + "max_completion_items": 6, // set max completion results len for each group: words, snippets, unicode-input |
| 39 | + "feature_words": false, // enable completion by word |
| 40 | + "feature_unicode_input": false, // enable "unicode input" |
| 41 | + "snippets_first": true, // completions will return before snippets by default |
| 42 | + "feature_snippets": true, // enable snippets |
| 43 | + "feature_paths": true // enable path completion |
| 44 | + } |
| 45 | + } |
| 46 | +} |
71 | 47 | ``` |
72 | 48 |
|
73 | 49 | ### Snippets |
74 | 50 |
|
75 | | -Read snippets from dir `~/.config/helix/snippets` or specify snippets path via `SNIPPETS_PATH` env. |
76 | | - |
77 | | -Currently, it supports our own `toml` format and vscode `json` (a basic effort). |
78 | | - |
79 | | -Filename used as snippet scope (language), filename `snippets.(toml|json)` will not attach scope to snippets. |
80 | | - |
81 | | -For example, snippets with the filename `python.toml` or `python.json` would have a `python` scope. |
82 | | - |
83 | | -Snippets format |
| 51 | +代码片段目录在 `~/.scls/snippets`, 示例(`~/.scls/snippets/go.toml`): |
84 | 52 |
|
85 | 53 | ```toml |
86 | 54 | [[snippets]] |
87 | | -prefix = "ld" |
88 | | -scope = [ "python" ] |
89 | | -body = 'log.debug("$1")' |
90 | | -``` |
91 | | - |
92 | | -### Use external snippets collections from git repos |
93 | | - |
94 | | -Configure sources in `~/.config/helix/external-snippets.toml` (or via env `EXTERNAL_SNIPPETS_CONFIG`) |
95 | | - |
96 | | -```toml |
97 | | -[[sources]] # list of sources to load |
98 | | -name = "friendly-snippets" # optional name shown on snippet description |
99 | | -git = "https://github.com/rafamadriz/friendly-snippets.git" # git repo with snippets collections |
100 | | - |
101 | | -[[sources.paths]] # list of paths to load on current source |
102 | | -scope = ["python"] # optional scopes for current snippets |
103 | | -path = "snippets/python/python.json" # where snippet file or dir located in repo |
104 | | -``` |
105 | | - |
106 | | - |
107 | | -Clone or update snippets source repos to `~/.config/helix/external-snippets/<repo path>` |
108 | | - |
109 | | -```console |
110 | | -$ simple-completion-language-server fetch-external-snippets |
111 | | -``` |
112 | | - |
113 | | - |
114 | | -Validate snippets |
115 | | - |
116 | | -```console |
117 | | -$ simple-completion-language-server validate-snippets |
118 | | -``` |
119 | | - |
120 | | -### Unicode input |
121 | | - |
122 | | -Read unicode input config as each file from dir `~/.config/helix/unicode-input` (or specify path via `UNICODE_INPUT_PATH` env). |
123 | | - |
124 | | -Unicode input format (toml key-value), for example `~/.config/helix/unicode-input/base.toml` |
125 | | - |
126 | | -```toml |
127 | | -alpha = "α" |
128 | | -betta = "β" |
129 | | -gamma = "γ" |
130 | | -fire = "🔥" |
| 55 | +prefix = "err" |
| 56 | +scope = [ "go" ] |
| 57 | +body = "if err := $1; err != nil {\n\t$2\t\n}" |
131 | 58 | ``` |
132 | 59 |
|
| 60 | +可以使用 |
133 | 61 |
|
134 | | -Validate unicode input config |
135 | | - |
136 | | -```console |
137 | | -$ simple-completion-language-server validate-unicode-input |
| 62 | +```sh |
| 63 | +simple-completion-language-server fetch-snippets |
138 | 64 | ``` |
139 | 65 |
|
140 | | - |
141 | | -### Similar projects |
142 | | - |
143 | | -- [metafates/buffer-language-server](https://github.com/metafates/buffer-language-server) |
144 | | -- [rajasegar/helix-snippets-ls](https://github.com/rajasegar/helix-snippets-ls) |
145 | | -- [quantonganh/snippets-ls](https://github.com/quantonganh/snippets-ls) |
146 | | -- [Stanislav-Lapata/snippets-ls](https://github.com/Stanislav-Lapata/snippets-ls) |
147 | | -- ...(please add another useful links here) |
148 | | - |
149 | | -### Useful snippets collections |
150 | | - |
151 | | -- [rafamadriz/friendly-snippets](https://github.com/rafamadriz/friendly-snippets) |
152 | | -- ...(please add another useful links here) |
| 66 | +命令来自动拉取 `https://github.com/rafamadriz/friendly-snippets` 仓库代码片段(它会自动生成配置文件) |
0 commit comments