-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from davelopez/add_setting_cleanable_props
Make `cleanable` properties user configurable
- Loading branch information
Showing
6 changed files
with
130 additions
and
23 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,81 @@ | ||
import { | ||
ClientCapabilities, | ||
Connection, | ||
DidChangeConfigurationNotification, | ||
DidChangeConfigurationParams, | ||
} from "vscode-languageserver"; | ||
|
||
/** Represents all the available settings of the extension. */ | ||
interface ExtensionSettings { | ||
cleaning: CleaningSettings; | ||
} | ||
|
||
/** Contains settings for workflow cleaning. */ | ||
interface CleaningSettings { | ||
/** A list of property names that will be removed from the workflow document when cleaning. */ | ||
cleanableProperties: string[]; | ||
} | ||
|
||
const defaultSettings: ExtensionSettings = { | ||
cleaning: { | ||
cleanableProperties: ["position", "uuid", "errors", "version"], | ||
}, | ||
}; | ||
|
||
let globalSettings: ExtensionSettings = defaultSettings; | ||
|
||
// Cache the settings of all open documents | ||
const documentSettingsCache: Map<string, ExtensionSettings> = new Map(); | ||
|
||
export class ConfigService { | ||
protected hasConfigurationCapability = false; | ||
|
||
constructor(public readonly connection: Connection) { | ||
this.connection.onInitialized(() => this.onInitialized()); | ||
this.connection.onDidChangeConfiguration((params) => this.onDidChangeConfiguration(params)); | ||
} | ||
|
||
public initialize(capabilities: ClientCapabilities): void { | ||
this.hasConfigurationCapability = !!(capabilities.workspace && !!capabilities.workspace.configuration); | ||
} | ||
|
||
public async getDocumentSettings(uri: string): Promise<ExtensionSettings> { | ||
if (!this.hasConfigurationCapability) { | ||
return Promise.resolve(globalSettings); | ||
} | ||
let result = documentSettingsCache.get(uri); | ||
if (!result) { | ||
result = await this.connection.workspace.getConfiguration({ | ||
scopeUri: uri, | ||
section: "galaxyWorkflows", | ||
}); | ||
result = result || globalSettings; | ||
this.addToDocumentConfigCache(uri, result); | ||
} | ||
return result; | ||
} | ||
|
||
public onDocumentClose(uri: string): void { | ||
documentSettingsCache.delete(uri); | ||
} | ||
|
||
private onInitialized(): void { | ||
if (this.hasConfigurationCapability) { | ||
this.connection.client.register(DidChangeConfigurationNotification.type); | ||
} | ||
} | ||
|
||
private onDidChangeConfiguration(params: DidChangeConfigurationParams): void { | ||
if (this.hasConfigurationCapability) { | ||
// Reset all cached document settings | ||
documentSettingsCache.clear(); | ||
} else { | ||
globalSettings = <ExtensionSettings>(params.settings.galaxyWorkflows || defaultSettings); | ||
} | ||
} | ||
|
||
private addToDocumentConfigCache(uri: string, settings: ExtensionSettings): void { | ||
if (uri.startsWith("temp")) return; // Do not cache config from temp files | ||
documentSettingsCache.set(uri, settings); | ||
} | ||
} |
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
4 changes: 2 additions & 2 deletions
4
server/src/commands/common.ts → server/src/services/common.ts
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import { ServerContext } from "../languageTypes"; | ||
import { GalaxyWorkflowLanguageServer } from "../server"; | ||
|
||
export abstract class CustomCommand extends ServerContext { | ||
export abstract class ServiceBase extends ServerContext { | ||
constructor(server: GalaxyWorkflowLanguageServer) { | ||
super(server); | ||
this.listenToRequests(); | ||
} | ||
|
||
/** | ||
* This method should call `this.connection.onRequest` to register | ||
* the proper callback for this command request. | ||
* the proper callback for this service request. | ||
*/ | ||
protected abstract listenToRequests(): void; | ||
} |
File renamed without changes.