Skip to content

Commit 697cb2e

Browse files
committed
fix type issues
1 parent 3284651 commit 697cb2e

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ dist/
66
scratch/
77
TODO
88
.DS_Store
9+

language-server/src/services/configuration.js

+8-19
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,19 @@ import ignore from "ignore";
1111
* @typedef {{
1212
* defaultDialect?: string;
1313
* schemaFilePatterns: string[];
14-
* detectIndentation: boolean;
15-
* }} DocumentSettings
16-
*/
17-
18-
/**
19-
* @typedef {{
20-
* jsonSchemaLanguageServer?: DocumentSettings;
21-
* }} Settings
22-
*/
23-
24-
/**
25-
* @typedef {{
14+
* detectIndentation?: boolean;
2615
* tabSize?: number;
2716
* insertSpaces?: boolean;
28-
* detectIndentation?: boolean;
29-
* endOfLine?: string;
30-
* }} IndentationSettings
17+
* endOfLine: string;
18+
* }} DocumentSettings
3119
*/
3220

21+
3322
export class Configuration {
3423
#server;
3524

3625
/** @type DocumentSettings | undefined */
3726
#settings;
38-
3927
/** @type Partial<DocumentSettings> */
4028
#defaultSettings;
4129

@@ -52,7 +40,8 @@ export class Configuration {
5240
this.#server = server;
5341

5442
this.#defaultSettings = {
55-
schemaFilePatterns: ["*.schema.json", "schema.json"]
43+
schemaFilePatterns: ["*.schema.json", "schema.json"],
44+
detectIndentation: true
5645
};
5746

5847
let hasDidChangeConfigurationCapability = false;
@@ -93,13 +82,13 @@ export class Configuration {
9382
{ section: "editor" },
9483
{ section: "files.eol" }
9584
]);
96-
const [extensionSettings, editorSettings, eol] = /** @type [DocumentSettings, IndentationSettings, string] */ (config);
97-
/** @type IndentationSettings */
85+
const [extensionSettings, editorSettings, eol] = /** @type [Partial<DocumentSettings> | null, Partial<DocumentSettings> | null, string | null] */ (config);
9886
const indentationSettings = {
9987
tabSize: editorSettings?.tabSize,
10088
insertSpaces: editorSettings?.insertSpaces,
10189
detectIndentation: editorSettings?.detectIndentation ?? this.#defaultSettings.detectIndentation,
10290
endOfLine: eol
91+
10392
};
10493

10594
const fullSettings = {

language-server/src/util/util.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import { join, relative } from "node:path";
55
import { URI } from "vscode-uri";
66
import detectIndent from "detect-indent";
77
import * as jsoncParser from "jsonc-parser";
8+
import os from "os";
89

910
/**
1011
* @import { TextEdit } from "vscode-languageserver"
1112
* @import { TextDocument } from "vscode-languageserver-textdocument"
1213
* @import { Ignore } from "ignore"
13-
* @import { IndentationSettings } from "../services/configuration.js"
14+
* @import { DocumentSettings} from "../services/configuration.js"
1415
* @import { SchemaNode as SchemaNodeType } from "../model/schema-node.js"
1516
*/
1617

@@ -114,7 +115,7 @@ export const readDirRecursive = async function* (path, filter, cwd) {
114115
}
115116
};
116117

117-
/** @type (textDocument: TextDocument, textEdit: TextEdit, settings: IndentationSettings) => TextEdit */
118+
/** @type (textDocument: TextDocument, textEdit: TextEdit, settings: DocumentSettings) => TextEdit */
118119
export const withFormatting = (textDocument, textEdit, settings) => {
119120
const indentation = settings.detectIndentation ? detectIndent(textDocument.getText()) : {
120121
amount: settings.tabSize,
@@ -125,7 +126,7 @@ export const withFormatting = (textDocument, textEdit, settings) => {
125126
insertSpaces: indentation.type === "space",
126127
tabSize: indentation.amount,
127128
keepLines: true,
128-
eol: settings.endOfLine
129+
eol: settings.endOfLine == "auto" ? os.EOL : settings.endOfLine
129130
};
130131

131132
const offset = textDocument.offsetAt(textEdit.range.start);

0 commit comments

Comments
 (0)