Skip to content

Commit d8a86d2

Browse files
committed
do some clean up
1 parent 1eb3c7b commit d8a86d2

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

language-server/src/services/configuration.js

+25-11
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ import ignore from "ignore";
1111
* @typedef {{
1212
* defaultDialect?: string;
1313
* schemaFilePatterns: string[];
14-
* tabSize: number;
15-
* insertSpaces: boolean;
1614
* detectIndentation: boolean;
17-
* endOfLine: string;
1815
* }} DocumentSettings
1916
*/
2017

@@ -24,6 +21,15 @@ import ignore from "ignore";
2421
* }} Settings
2522
*/
2623

24+
/**
25+
* @typedef {{
26+
* tabSize?: number;
27+
* insertSpaces?: boolean;
28+
* detectIndentation?: boolean;
29+
* endOfLine?: string;
30+
* }} IndentationSettings
31+
*/
32+
2733
export class Configuration {
2834
#server;
2935

@@ -68,7 +74,15 @@ export class Configuration {
6874
this.#didChangeConfigurationHandlers = [];
6975

7076
this.#server.onDidChangeConfiguration((params) => {
71-
this.#settings = undefined;
77+
/** @type unknown */
78+
const settings = params.settings;
79+
80+
/** @type unknown */
81+
const fullSettings = {
82+
...this.#defaultSettings,
83+
.../** @type Settings */(settings).jsonSchemaLanguageServer
84+
};
85+
this.#settings = /** @type DocumentSettings */ (fullSettings);
7286
this.#matcher = undefined;
7387

7488
for (const handler of this.#didChangeConfigurationHandlers) {
@@ -77,20 +91,20 @@ export class Configuration {
7791
});
7892
}
7993

80-
/** @type (documentUri?: string) => Promise<DocumentSettings> */
81-
async get(documentUri) {
94+
/** @type () => Promise<DocumentSettings> */
95+
async get() {
8296
if (!this.#settings) {
8397
/** @type {unknown[]} */
8498
const config = await this.#server.workspace.getConfiguration([
8599
{ section: "jsonSchemaLanguageServer" },
86-
{ section: "editor", scopeUri: documentUri },
100+
{ section: "editor" },
87101
{ section: "files.eol" }
88102
]);
89-
const [extensionSettings, editorSettings, eol] = /** @type [{ defaultDialect?: string; schemaFilePatterns?: string[] },{ tabSize?: number; insertSpaces?: boolean; detectIndentation?: boolean }, string ] */ (config);
90-
/** @type {{ tabSize?: number; insertSpaces?: boolean; detectIndentation?: boolean, endOfLine?: string }} */
103+
const [extensionSettings, editorSettings, eol] = /** @type [DocumentSettings, IndentationSettings, string] */ (config);
104+
/** @type IndentationSettings */
91105
const indentationSettings = {
92-
tabSize: editorSettings?.tabSize ?? this.#defaultSettings.tabSize,
93-
insertSpaces: editorSettings?.insertSpaces ?? this.#defaultSettings.insertSpaces,
106+
tabSize: editorSettings?.tabSize,
107+
insertSpaces: editorSettings?.insertSpaces,
94108
detectIndentation: editorSettings?.detectIndentation ?? this.#defaultSettings.detectIndentation,
95109
endOfLine: eol
96110
};

language-server/src/util/util.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as jsoncParser from "jsonc-parser";
1010
* @import { TextEdit } from "vscode-languageserver"
1111
* @import { TextDocument } from "vscode-languageserver-textdocument"
1212
* @import { Ignore } from "ignore"
13-
* @import { DocumentSettings } from "../services/configuration.js"
13+
* @import { IndentationSettings } from "../services/configuration.js"
1414
* @import { SchemaNode as SchemaNodeType } from "../model/schema-node.js"
1515
*/
1616

@@ -114,7 +114,7 @@ export const readDirRecursive = async function* (path, filter, cwd) {
114114
}
115115
};
116116

117-
/** @type (textDocument: TextDocument, textEdit: TextEdit, settings: DocumentSettings) => TextEdit */
117+
/** @type (textDocument: TextDocument, textEdit: TextEdit, settings: IndentationSettings) => TextEdit */
118118
export const withFormatting = (textDocument, textEdit, settings) => {
119119
const indentation = settings.detectIndentation ? detectIndent(textDocument.getText()) : {
120120
amount: settings.tabSize,

0 commit comments

Comments
 (0)