-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
339ac62
commit 8dd3202
Showing
25 changed files
with
201 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { fileURLToPath } from "node:url"; | ||
import picomatch from "picomatch"; | ||
|
||
/** | ||
* @import { Connection, DidChangeConfigurationParams, NotificationHandler } from "vscode-languageserver" | ||
*/ | ||
|
||
|
||
/** | ||
* @typedef {{ | ||
* defaultDialect?: string; | ||
* schemaFilePatterns: string[]; | ||
* }} DocumentSettings | ||
*/ | ||
|
||
export class Configuration { | ||
#connection; | ||
|
||
/** @type DocumentSettings | undefined */ | ||
#settings; | ||
/** @type Partial<DocumentSettings> */ | ||
#defaultSettings; | ||
|
||
/** @type ((uri: string) => boolean) | undefined */ | ||
#matcher; | ||
|
||
/** @type NotificationHandler<DidChangeConfigurationParams>[] */ | ||
#didChangeConfigurationHandlers; | ||
|
||
/** | ||
* @param {Connection} connection | ||
*/ | ||
constructor(connection) { | ||
this.#connection = connection; | ||
|
||
this.#defaultSettings = { | ||
schemaFilePatterns: ["**/*.schema.json", "**/schema.json"] | ||
}; | ||
|
||
this.#didChangeConfigurationHandlers = []; | ||
|
||
this.#connection.onDidChangeConfiguration((params) => { | ||
this.#settings = { ...this.#defaultSettings, ...params.settings.jsonSchemaLanguageServer }; | ||
this.#matcher = undefined; | ||
|
||
for (const handler of this.#didChangeConfigurationHandlers) { | ||
handler(params); | ||
} | ||
}); | ||
} | ||
|
||
/** @type () => Promise<DocumentSettings> */ | ||
async get() { | ||
if (!this.#settings) { | ||
const result = await this.#connection.workspace.getConfiguration({ | ||
section: "jsonSchemaLanguageServer" | ||
}) ?? {}; | ||
this.#settings = { ...this.#defaultSettings, ...result }; | ||
this.#matcher = undefined; | ||
} | ||
|
||
return /** @type DocumentSettings */ (this.#settings); | ||
} | ||
|
||
/** @type (uri: string) => Promise<boolean> */ | ||
async isSchema(uri) { | ||
if (!this.#matcher) { | ||
const { schemaFilePatterns } = await this.get(); | ||
this.#matcher = picomatch(schemaFilePatterns); | ||
} | ||
|
||
const path = fileURLToPath(uri); | ||
return this.#matcher(path); | ||
} | ||
|
||
/** @type (handler: NotificationHandler<DidChangeConfigurationParams>) => void */ | ||
onDidChangeConfiguration(handler) { | ||
this.#didChangeConfigurationHandlers.push(handler); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.