|
| 1 | +use lapce_plugin::psp_types::lsp_types::Url; |
1 | 2 | use serde::{Deserialize, Serialize};
|
2 |
| -use serde_json::{json, Value}; |
| 3 | +use serde_json::Value; |
3 | 4 |
|
4 | 5 | #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
5 | 6 | #[serde(rename_all = "camelCase")]
|
6 |
| -enum TextDocumentSyncKind { |
7 |
| - None = 0, |
8 |
| - Full = 1, |
9 |
| - Incremental = 2, |
10 |
| -} |
11 |
| - |
12 |
| -#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] |
13 |
| -#[serde(rename_all = "camelCase")] |
14 |
| -/// Ts server path |
15 |
| -struct TypescriptPath { |
16 |
| - /** |
17 |
| - * Path to tsserverlibrary.js / tsserver.js / typescript.js |
18 |
| - * @example |
19 |
| - * '/usr/local/lib/node_modules/typescript/lib/tsserverlibrary.js' // use global typescript install |
20 |
| - * 'typescript/lib/tsserverlibrary.js' // if `typescript` exist in `@volar/vue-lannguage-server` itself node_modules directory |
21 |
| - * '../../../typescript/lib/tsserverlibrary.js' // relative path to @volar/vue-language-server/out/index.js |
22 |
| - */ |
23 |
| - serverPath: String, |
24 |
| - /** |
25 |
| - * Path to lib/xxx/diagnosticMessages.generated.json |
26 |
| - * @example |
27 |
| - * '/usr/local/lib/node_modules/typescript/lib/ja/diagnosticMessages.generated.json' // use global typescript install |
28 |
| - * 'typescript/lib/ja/diagnosticMessages.generated.json' // if `typescript` exist in `@volar/vue-lannguage-server` itself node_modules directory |
29 |
| - * '../../../typescript/lib/ja/diagnosticMessages.generated.json' // relative path to @volar/vue-language-server/out/index.js |
30 |
| - */ |
31 |
| - localizedPath: Option<String>, |
32 |
| -} |
33 |
| - |
34 |
| -/// both | kebabCase | pascalCase |
35 |
| -
|
36 |
| -#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] |
37 |
| -#[serde(rename_all = "camelCase")] |
38 |
| -pub enum DefaultTagNameCase { |
39 |
| - both, |
40 |
| - kebabCase, |
41 |
| - pascalCase, |
42 |
| -} |
43 |
| - |
44 |
| -#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] |
45 |
| -#[serde(rename_all = "camelCase")] |
46 |
| -pub enum DefaultAttrNameCase { |
47 |
| - kebabCase, |
48 |
| - camelCase, |
49 |
| -} |
50 |
| - |
51 |
| -#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] |
52 |
| -#[serde(rename_all = "camelCase")] |
53 |
| -pub struct Completion { |
54 |
| - pub defaultTagNameCase: DefaultTagNameCase, |
55 |
| - pub defaultAttrNameCase: DefaultAttrNameCase, |
56 |
| - /** |
57 |
| - * {@link __requests.GetDocumentNameCasesRequest} |
58 |
| - */ |
59 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
60 |
| - pub getDocumentNameCasesRequest: Option<bool>, |
61 |
| - /** |
62 |
| - * {@link __requests.GetDocumentSelectionRequest} |
63 |
| - * */ |
64 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
65 |
| - pub getDocumentSelectionRequest: Option<bool>, |
66 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
67 |
| - pub ignoreTriggerCharacters: Option<String>, |
| 7 | +struct TypescriptSDK { |
| 8 | + tsdk: String, |
68 | 9 | }
|
69 | 10 |
|
70 | 11 | #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
71 | 12 | #[serde(rename_all = "camelCase")]
|
72 |
| -pub struct CodeLens { |
73 |
| - showReferencesNotification: Option<bool>, |
| 13 | +enum ServerMode { |
| 14 | + Semantic = 0, |
| 15 | + // PartialSemantic = 1, // not support yet |
| 16 | + Syntactic = 2, |
74 | 17 | }
|
75 |
| - |
76 | 18 | #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
77 | 19 | #[serde(rename_all = "camelCase")]
|
78 |
| -pub struct SchemaRequestService { |
79 |
| - pub getDocumentContentRequest: Option<bool>, |
80 |
| -} |
81 |
| -/** |
82 |
| - * typescript, html, css... language service will be create in server if this option is not null |
83 |
| - */ |
84 |
| -#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] |
85 |
| -#[serde(rename_all = "camelCase")] |
86 |
| -pub struct LanguageFeatures { |
87 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
88 |
| - references: Option<bool>, |
89 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
90 |
| - implementation: Option<bool>, |
91 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
92 |
| - definition: Option<bool>, |
93 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
94 |
| - typeDefinition: Option<bool>, |
95 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
96 |
| - callHierarchy: Option<bool>, |
97 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
98 |
| - hover: Option<bool>, |
99 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
100 |
| - rename: Option<bool>, |
101 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
102 |
| - renameFileRefactoring: Option<bool>, |
103 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
104 |
| - signatureHelp: Option<bool>, |
105 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
106 |
| - // completion: Option<Completion>, |
107 |
| - completion: Option<bool>, |
108 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
109 |
| - documentHighlight: Option<bool>, |
110 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
111 |
| - documentLink: Option<bool>, |
112 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
113 |
| - workspaceSymbol: Option<bool>, |
114 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
115 |
| - codeLens: Option<CodeLens>, |
116 |
| - // codeLens: Option<bool>, |
117 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
118 |
| - semanticTokens: Option<bool>, |
119 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
120 |
| - codeAction: Option<bool>, |
121 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
122 |
| - inlayHints: Option<bool>, |
123 |
| - /// 诊断 |
124 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
125 |
| - diagnostics: Option<bool>, |
126 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
127 |
| - // schemaRequestService: Option<SchemaRequestService>, |
128 |
| - schemaRequestService: Option<bool>, |
| 20 | +enum DiagnosticModel { |
| 21 | + None = 0, |
| 22 | + Push = 1, |
| 23 | + Pull = 2, |
129 | 24 | }
|
130 |
| - |
131 | 25 | #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
132 | 26 | #[serde(rename_all = "camelCase")]
|
133 |
| -pub struct DocumentFeatures { |
134 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
135 |
| - selectionRange: Option<bool>, |
| 27 | +pub struct LanguageServerInitializationOptions { |
| 28 | + typescript: TypescriptSDK, |
136 | 29 | #[serde(skip_serializing_if = "Option::is_none")]
|
137 |
| - foldingRange: Option<bool>, |
| 30 | + serverMode: Option<ServerMode>, |
138 | 31 | #[serde(skip_serializing_if = "Option::is_none")]
|
139 |
| - linkedEditingRange: Option<bool>, |
| 32 | + diagnosticModel: Option<DiagnosticModel>, |
140 | 33 | #[serde(skip_serializing_if = "Option::is_none")]
|
141 |
| - documentSymbol: Option<bool>, |
142 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
143 |
| - documentColor: Option<bool>, |
144 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
145 |
| - documentFormatting: Option<bool>, |
| 34 | + textDocumentSync: Option<u8>, |
146 | 35 | }
|
147 |
| - |
148 |
| -#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] |
149 |
| -#[serde(rename_all = "camelCase")] |
150 |
| -struct ServerInitializationOptions { |
151 |
| - // textDocumentSync: TextDocumentSyncKind, |
152 |
| - typescript: TypescriptPath, |
153 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
154 |
| - languageFeatures: Option<LanguageFeatures>, |
155 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
156 |
| - documentFeatures: Option<DocumentFeatures>, |
157 |
| -} |
158 |
| -pub fn get_main_language_feature() -> LanguageFeatures { |
159 |
| - LanguageFeatures { |
160 |
| - references: Some(true), |
161 |
| - // 不存在 |
162 |
| - implementation: Some(true), |
163 |
| - definition: Some(true), |
164 |
| - typeDefinition: Some(true), |
165 |
| - callHierarchy: Some(true), |
166 |
| - hover: None, |
167 |
| - rename: Some(true), |
168 |
| - renameFileRefactoring: Some(true), |
169 |
| - signatureHelp: Some(true), |
170 |
| - codeAction: Some(true), |
171 |
| - workspaceSymbol: Some(true), |
172 |
| - // completion: Some(Completion { |
173 |
| - // defaultTagNameCase: DefaultTagNameCase::both, |
174 |
| - // defaultAttrNameCase: DefaultAttrNameCase::kebabCase, |
175 |
| - // getDocumentNameCasesRequest: Some(true), |
176 |
| - // getDocumentSelectionRequest: Some(true), |
177 |
| - // ignoreTriggerCharacters: None, |
178 |
| - // }), |
179 |
| - completion: Some(true), |
180 |
| - schemaRequestService: Some(true), |
181 |
| - documentHighlight: Some(true), |
182 |
| - documentLink: Some(true), |
183 |
| - codeLens: Some(CodeLens { |
184 |
| - showReferencesNotification: Some(true), |
185 |
| - }), |
186 |
| - // 语义标记 |
187 |
| - semanticTokens: Some(false), |
188 |
| - inlayHints: Some(true), |
189 |
| - diagnostics: Some(true), |
190 |
| - } |
191 |
| -} |
192 |
| - |
193 |
| -pub fn get_second_language_feature() -> LanguageFeatures { |
194 |
| - LanguageFeatures { |
195 |
| - documentHighlight: Some(true), |
196 |
| - documentLink: Some(true), |
197 |
| - codeLens: Some(CodeLens { |
198 |
| - showReferencesNotification: Some(true), |
199 |
| - }), |
200 |
| - semanticTokens: Some(true), |
201 |
| - // 不存在 |
202 |
| - inlayHints: Some(true), |
203 |
| - diagnostics: Some(true), |
204 |
| - schemaRequestService: None, |
205 |
| - references: None, |
206 |
| - implementation: None, |
207 |
| - definition: None, |
208 |
| - typeDefinition: None, |
209 |
| - callHierarchy: None, |
210 |
| - hover: None, |
211 |
| - rename: None, |
212 |
| - renameFileRefactoring: None, |
213 |
| - signatureHelp: None, |
214 |
| - completion: None, |
215 |
| - workspaceSymbol: None, |
216 |
| - codeAction: None, |
217 |
| - } |
218 |
| -} |
219 |
| - |
220 |
| -pub fn get_doc_feature() -> DocumentFeatures { |
221 |
| - DocumentFeatures { |
222 |
| - // allowedLanguageIds: Some(vec![ |
223 |
| - // "vue".to_owned(), |
224 |
| - // "javascript".to_owned(), |
225 |
| - // "typescript".to_owned(), |
226 |
| - // "javascriptreact".to_owned(), |
227 |
| - // "typescriptreact".to_owned(), |
228 |
| - // ]), |
229 |
| - // allowedLanguageIds: Some(), |
230 |
| - // selectionRange: Some(true), |
231 |
| - // foldingRange: Some(true), |
232 |
| - // linkedEditingRange: Some(true), |
233 |
| - // documentSymbol: Some(true), |
234 |
| - // documentColor: Some(true), |
235 |
| - // // 没有格式胡 |
236 |
| - // documentFormatting: Some(true), |
237 |
| - selectionRange: Some(true), |
238 |
| - foldingRange: Some(true), |
239 |
| - linkedEditingRange: Some(true), |
240 |
| - documentSymbol: Some(true), |
241 |
| - documentColor: Some(true), |
242 |
| - documentFormatting: Some(true), |
243 |
| - } |
244 |
| -} |
245 |
| - |
246 |
| -pub enum LanguageOptionEnum { |
247 |
| - main_language_feature, |
248 |
| - second_language_feature, |
249 |
| - document_feature, |
250 |
| -} |
251 |
| - |
252 |
| -pub fn get_initialization_options(name: LanguageOptionEnum) -> Option<Value> { |
253 |
| - let language_features = match name { |
254 |
| - LanguageOptionEnum::main_language_feature => Some(get_main_language_feature()), |
255 |
| - LanguageOptionEnum::second_language_feature => Some(get_second_language_feature()), |
256 |
| - LanguageOptionEnum::document_feature => None, |
257 |
| - }; |
258 |
| - let document_features = match name { |
259 |
| - LanguageOptionEnum::main_language_feature => None, |
260 |
| - LanguageOptionEnum::second_language_feature => None, |
261 |
| - LanguageOptionEnum::document_feature => Some(get_doc_feature()), |
262 |
| - }; |
263 |
| - |
264 |
| - let initialization_options = ServerInitializationOptions { |
265 |
| - // textDocumentSync: TextDocumentSyncKind::Incremental, |
266 |
| - typescript: TypescriptPath { |
267 |
| - serverPath: |
268 |
| - "/Users/skymac/Library/pnpm/global/5/.pnpm/typescript@4.8.4/node_modules/typescript/lib/tsserverlibrary.js" |
269 |
| - .to_owned(), |
270 |
| - // serverPath: "/Users/xiaoxin/Library/pnpm/global/5/.pnpm/typescript@4.7.4/node_modules/typescript/lib/tsserverlibrary.js".to_owned(), |
271 |
| - localizedPath: None, // localizedPath: Some( |
272 |
| - // "/Users/skymac/node_modules/typescript/lib/zh-cn/diagnosticMessages.generated.json" |
273 |
| - // .to_owned(), |
274 |
| - // ), |
275 |
| - }, |
276 |
| - languageFeatures: Some(get_main_language_feature()), |
277 |
| - documentFeatures: Some(get_doc_feature()), |
| 36 | +pub fn get_language_server_init_options(root_url: Option<Url>) -> Option<Value> { |
| 37 | + let root_url = root_url.unwrap(); |
| 38 | + let tsdk = root_url |
| 39 | + .join("node_modules/typescript/lib") |
| 40 | + .unwrap() |
| 41 | + .to_file_path() |
| 42 | + .unwrap() |
| 43 | + .to_str() |
| 44 | + .unwrap() |
| 45 | + .to_string(); |
| 46 | + let initialization_options = LanguageServerInitializationOptions { |
| 47 | + typescript: TypescriptSDK { tsdk }, |
| 48 | + serverMode: None, |
| 49 | + diagnosticModel: None, |
| 50 | + textDocumentSync: None, |
278 | 51 | };
|
279 | 52 | serde_json::to_value(&initialization_options).ok()
|
280 | 53 | }
|
281 |
| - |
282 |
| -fn find_volar_path(root_path: Option<String>) {} |
0 commit comments