1
1
import { DidChangeConfigurationNotification } from "vscode-languageserver" ;
2
2
import ignore from "ignore" ;
3
+ import { pick } from "../util/util.js" ;
3
4
4
5
/**
5
6
* @import { DidChangeConfigurationParams, NotificationHandler } from "vscode-languageserver"
@@ -11,20 +12,42 @@ import ignore from "ignore";
11
12
* @typedef {{
12
13
* defaultDialect?: string;
13
14
* schemaFilePatterns: string[];
14
- * detectIndentation?: boolean;
15
+ * }} LanguageServerSettings
16
+ */
17
+
18
+ /**
19
+ * @typedef {{
15
20
* tabSize?: number;
16
21
* insertSpaces?: boolean;
17
- * endOfLine: string;
18
- * }} DocumentSettings
22
+ * detectIndentation: boolean;
23
+ * }} EditorSettings
24
+ */
25
+
26
+ /**
27
+ * @typedef {{
28
+ * eol?: string;
29
+ * }} FilesSettings
30
+ */
31
+
32
+ /**
33
+ * @typedef {LanguageServerSettings & EditorSettings & FilesSettings } DocumentSettings
19
34
*/
20
35
36
+ /**
37
+ * @typedef {[
38
+ * Partial<LanguageServerSettings> | null,
39
+ * Partial<EditorSettings> | null,
40
+ * Partial<FilesSettings> | null
41
+ * ]} Settings
42
+ */
21
43
22
44
export class Configuration {
23
45
#server;
24
46
25
47
/** @type DocumentSettings | undefined */
26
48
#settings;
27
- /** @type Partial<DocumentSettings> */
49
+
50
+ /** @type DocumentSettings */
28
51
#defaultSettings;
29
52
30
53
/** @type ((uri: string) => boolean) | undefined */
@@ -76,32 +99,22 @@ export class Configuration {
76
99
/** @type () => Promise<DocumentSettings> */
77
100
async get ( ) {
78
101
if ( ! this . #settings) {
79
- /** @type {unknown[] } */
80
- const config = await this . #server. workspace . getConfiguration ( [
102
+ const settings = /** @type Settings */ ( await this . #server. workspace . getConfiguration ( [
81
103
{ section : "jsonSchemaLanguageServer" } ,
82
104
{ section : "editor" } ,
83
- { section : "files.eol" }
84
- ] ) ;
85
- const [ extensionSettings , editorSettings , eol ] = /** @type [Partial<DocumentSettings> | null, Partial<DocumentSettings> | null, string | null] */ ( config ) ;
86
- const indentationSettings = {
87
- tabSize : editorSettings ?. tabSize ,
88
- insertSpaces : editorSettings ?. insertSpaces ,
89
- detectIndentation : editorSettings ?. detectIndentation ?? this . #defaultSettings. detectIndentation ,
90
- endOfLine : eol
105
+ { section : "files" }
106
+ ] ) ) ;
107
+ const [ languageServerSettings , editorSettings , filesSettings ] = settings ;
91
108
92
- } ;
93
-
94
- const fullSettings = {
109
+ this . #settings = {
95
110
...this . #defaultSettings,
96
- ...extensionSettings ,
97
- ...indentationSettings
111
+ ...languageServerSettings ,
112
+ ...pick ( editorSettings ?? { } , "tabSize" , "insertSpaces" , "detectIndentation" ) ,
113
+ ...pick ( filesSettings ?? { } , "eol" )
98
114
} ;
99
-
100
- this . #settings = /** @type DocumentSettings */ ( fullSettings ) ;
101
- this . #matcher = undefined ;
102
115
}
103
116
104
- return /** @type DocumentSettings */ ( this . #settings) ;
117
+ return this . #settings;
105
118
}
106
119
107
120
/** @type (uri: string) => Promise<boolean> */
0 commit comments