Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions sources/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as os from "os";
import * as path from "path";
import * as qub from "qub";

/**
Expand Down Expand Up @@ -370,6 +372,15 @@ export abstract class LanguageExtension<ParsedDocumentType> implements Disposabl
return this._extensionVersion;
}

/**
* Get the file path to the settings file for this extension. This is the JSON file where
* details can be kept that need to be saved across VS Code sessions. This file may or may not
* exist.
*/
public getSettingsFilePath(): string {
return path.join(os.homedir(), ".vscode", this.name + ".json");
}

public getConfigurationValue<T>(propertyPath: string, defaultValue?: T): T {
const configuration: Configuration = this.getConfiguration();
return configuration ? configuration.get<T>(`${this._extensionName}.${propertyPath}`, defaultValue) : defaultValue;
Expand Down
6 changes: 6 additions & 0 deletions tests/mocks.tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as assert from "assert";
import * as os from "os";
import * as path from "path";
import * as qub from "qub";

import * as interfaces from "../sources/interfaces";
Expand Down Expand Up @@ -758,6 +760,8 @@ suite("Mocks", () => {
const extension = new mocks.PlaintextLanguageExtension(undefined);
assert.deepStrictEqual(extension.name, "Plaintext Tools");
assert.deepStrictEqual(extension.version, "1.0.0");

assert.deepStrictEqual(extension.getSettingsFilePath(), path.join(os.homedir(), ".vscode", "Plaintext Tools.json"));
});

test("with a platform", () => {
Expand All @@ -766,6 +770,8 @@ suite("Mocks", () => {
assert.deepStrictEqual(extension.name, "Plaintext Tools");
assert.deepStrictEqual(extension.version, "1.0.0");

assert.deepStrictEqual(extension.getSettingsFilePath(), path.join(os.homedir(), ".vscode", "Plaintext Tools.json"));

platform.setActiveTextEditor(new mocks.TextEditor(undefined));
platform.setActiveTextEditor(undefined);
platform.setConfiguration(new mocks.Configuration({}));
Expand Down