From bcf9df598af438912fbc7c08652426fbce17535e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Cie=C5=9Blak?= Date: Sat, 23 Sep 2017 22:47:42 +0200 Subject: [PATCH 1/4] Add editorFileExtension when clause context --- src/vs/editor/common/editorContextKeys.ts | 1 + src/vs/editor/common/modes/editorModeContext.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/vs/editor/common/editorContextKeys.ts b/src/vs/editor/common/editorContextKeys.ts index 8843cf821d4..0aa240df5e4 100644 --- a/src/vs/editor/common/editorContextKeys.ts +++ b/src/vs/editor/common/editorContextKeys.ts @@ -28,6 +28,7 @@ export namespace EditorContextKeys { // -- mode context keys export const languageId = new RawContextKey('editorLangId', undefined); + export const fileExtension = new RawContextKey('editorFileExtension', undefined); export const hasCompletionItemProvider = new RawContextKey('editorHasCompletionItemProvider', undefined); export const hasCodeActionsProvider = new RawContextKey('editorHasCodeActionsProvider', undefined); export const hasCodeLensProvider = new RawContextKey('editorHasCodeLensProvider', undefined); diff --git a/src/vs/editor/common/modes/editorModeContext.ts b/src/vs/editor/common/modes/editorModeContext.ts index a22237cf04e..a52892edccf 100644 --- a/src/vs/editor/common/modes/editorModeContext.ts +++ b/src/vs/editor/common/modes/editorModeContext.ts @@ -16,6 +16,7 @@ export class EditorModeContext extends Disposable { private _editor: ICommonCodeEditor; private _langId: IContextKey; + private _fileExtension: IContextKey; private _hasCompletionItemProvider: IContextKey; private _hasCodeActionsProvider: IContextKey; private _hasCodeLensProvider: IContextKey; @@ -40,6 +41,7 @@ export class EditorModeContext extends Disposable { this._editor = editor; this._langId = EditorContextKeys.languageId.bindTo(contextKeyService); + this._fileExtension = EditorContextKeys.fileExtension.bindTo(contextKeyService); this._hasCompletionItemProvider = EditorContextKeys.hasCompletionItemProvider.bindTo(contextKeyService); this._hasCodeActionsProvider = EditorContextKeys.hasCodeActionsProvider.bindTo(contextKeyService); this._hasCodeLensProvider = EditorContextKeys.hasCodeLensProvider.bindTo(contextKeyService); @@ -87,6 +89,7 @@ export class EditorModeContext extends Disposable { reset() { this._langId.reset(); + this._fileExtension.reset(); this._hasCompletionItemProvider.reset(); this._hasCodeActionsProvider.reset(); this._hasCodeLensProvider.reset(); @@ -111,6 +114,7 @@ export class EditorModeContext extends Disposable { return; } this._langId.set(model.getLanguageIdentifier().language); + this._fileExtension.set(model.uri.path.split('.').pop()); this._hasCompletionItemProvider.set(modes.SuggestRegistry.has(model)); this._hasCodeActionsProvider.set(modes.CodeActionProviderRegistry.has(model)); this._hasCodeLensProvider.set(modes.CodeLensProviderRegistry.has(model)); From c5d19f539c838240e1becaacc1fcb2f9471113b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Cie=C5=9Blak?= Date: Wed, 27 Sep 2017 17:23:11 +0200 Subject: [PATCH 2/4] Add extension context to ResourceContextKey --- src/vs/workbench/common/resources.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/vs/workbench/common/resources.ts b/src/vs/workbench/common/resources.ts index 34b7d02d846..67857f78e7c 100644 --- a/src/vs/workbench/common/resources.ts +++ b/src/vs/workbench/common/resources.ts @@ -23,11 +23,13 @@ export class ResourceContextKey implements IContextKey { static Filename = new RawContextKey('resourceFilename', undefined); static LangId = new RawContextKey('resourceLangId', undefined); static Resource = new RawContextKey('resource', undefined); + static Extension = new RawContextKey('resourceExtension', undefined); private _resourceKey: IContextKey; private _schemeKey: IContextKey; private _filenameKey: IContextKey; private _langIdKey: IContextKey; + private _extensionKey: IContextKey; constructor( @IContextKeyService contextKeyService: IContextKeyService, @@ -37,6 +39,7 @@ export class ResourceContextKey implements IContextKey { this._filenameKey = ResourceContextKey.Filename.bindTo(contextKeyService); this._langIdKey = ResourceContextKey.LangId.bindTo(contextKeyService); this._resourceKey = ResourceContextKey.Resource.bindTo(contextKeyService); + this._extensionKey = ResourceContextKey.Extension.bindTo(contextKeyService); } set(value: URI) { @@ -44,12 +47,14 @@ export class ResourceContextKey implements IContextKey { this._schemeKey.set(value && value.scheme); this._filenameKey.set(value && basename(value.fsPath)); this._langIdKey.set(value && this._modeService.getModeIdByFilenameOrFirstLine(value.fsPath)); + this._extensionKey.set(value && paths.extname(value.fsPath)); } reset(): void { this._schemeKey.reset(); this._langIdKey.reset(); this._resourceKey.reset(); + this._extensionKey.reset(); } public get(): URI { From e2f198edf12111251ffe94f9ad5490bda2e9928c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Cie=C5=9Blak?= Date: Wed, 27 Sep 2017 17:28:30 +0200 Subject: [PATCH 3/4] Rename context and small fixes --- src/vs/editor/common/editorContextKeys.ts | 2 +- src/vs/editor/common/modes/editorModeContext.ts | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/vs/editor/common/editorContextKeys.ts b/src/vs/editor/common/editorContextKeys.ts index 0aa240df5e4..4283b4e989a 100644 --- a/src/vs/editor/common/editorContextKeys.ts +++ b/src/vs/editor/common/editorContextKeys.ts @@ -28,7 +28,7 @@ export namespace EditorContextKeys { // -- mode context keys export const languageId = new RawContextKey('editorLangId', undefined); - export const fileExtension = new RawContextKey('editorFileExtension', undefined); + export const editorExtension = new RawContextKey('editorExtension', undefined); export const hasCompletionItemProvider = new RawContextKey('editorHasCompletionItemProvider', undefined); export const hasCodeActionsProvider = new RawContextKey('editorHasCodeActionsProvider', undefined); export const hasCodeLensProvider = new RawContextKey('editorHasCodeLensProvider', undefined); diff --git a/src/vs/editor/common/modes/editorModeContext.ts b/src/vs/editor/common/modes/editorModeContext.ts index a52892edccf..b503700f9d7 100644 --- a/src/vs/editor/common/modes/editorModeContext.ts +++ b/src/vs/editor/common/modes/editorModeContext.ts @@ -10,13 +10,14 @@ import * as modes from 'vs/editor/common/modes'; import { ICommonCodeEditor } from 'vs/editor/common/editorCommon'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { Schemas } from 'vs/base/common/network'; +import * as paths from 'vs/base/common/paths'; export class EditorModeContext extends Disposable { private _editor: ICommonCodeEditor; private _langId: IContextKey; - private _fileExtension: IContextKey; + private _editorExtension: IContextKey; private _hasCompletionItemProvider: IContextKey; private _hasCodeActionsProvider: IContextKey; private _hasCodeLensProvider: IContextKey; @@ -41,7 +42,7 @@ export class EditorModeContext extends Disposable { this._editor = editor; this._langId = EditorContextKeys.languageId.bindTo(contextKeyService); - this._fileExtension = EditorContextKeys.fileExtension.bindTo(contextKeyService); + this._editorExtension = EditorContextKeys.editorExtension.bindTo(contextKeyService); this._hasCompletionItemProvider = EditorContextKeys.hasCompletionItemProvider.bindTo(contextKeyService); this._hasCodeActionsProvider = EditorContextKeys.hasCodeActionsProvider.bindTo(contextKeyService); this._hasCodeLensProvider = EditorContextKeys.hasCodeLensProvider.bindTo(contextKeyService); @@ -89,7 +90,7 @@ export class EditorModeContext extends Disposable { reset() { this._langId.reset(); - this._fileExtension.reset(); + this._editorExtension.reset(); this._hasCompletionItemProvider.reset(); this._hasCodeActionsProvider.reset(); this._hasCodeLensProvider.reset(); @@ -114,7 +115,7 @@ export class EditorModeContext extends Disposable { return; } this._langId.set(model.getLanguageIdentifier().language); - this._fileExtension.set(model.uri.path.split('.').pop()); + this._editorExtension.set(paths.extname(model.uri.fsPath)); this._hasCompletionItemProvider.set(modes.SuggestRegistry.has(model)); this._hasCodeActionsProvider.set(modes.CodeActionProviderRegistry.has(model)); this._hasCodeLensProvider.set(modes.CodeLensProviderRegistry.has(model)); From 0f4fdb82cf14429b35614a82ac8aab336c61ee06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Cie=C5=9Blak?= Date: Fri, 6 Oct 2017 12:48:17 +0200 Subject: [PATCH 4/4] Remove new context from editorContextKeys and rename --- src/vs/editor/common/editorContextKeys.ts | 1 - src/vs/editor/common/modes/editorModeContext.ts | 5 ----- src/vs/workbench/common/resources.ts | 2 +- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/vs/editor/common/editorContextKeys.ts b/src/vs/editor/common/editorContextKeys.ts index 4283b4e989a..8843cf821d4 100644 --- a/src/vs/editor/common/editorContextKeys.ts +++ b/src/vs/editor/common/editorContextKeys.ts @@ -28,7 +28,6 @@ export namespace EditorContextKeys { // -- mode context keys export const languageId = new RawContextKey('editorLangId', undefined); - export const editorExtension = new RawContextKey('editorExtension', undefined); export const hasCompletionItemProvider = new RawContextKey('editorHasCompletionItemProvider', undefined); export const hasCodeActionsProvider = new RawContextKey('editorHasCodeActionsProvider', undefined); export const hasCodeLensProvider = new RawContextKey('editorHasCodeLensProvider', undefined); diff --git a/src/vs/editor/common/modes/editorModeContext.ts b/src/vs/editor/common/modes/editorModeContext.ts index b503700f9d7..a22237cf04e 100644 --- a/src/vs/editor/common/modes/editorModeContext.ts +++ b/src/vs/editor/common/modes/editorModeContext.ts @@ -10,14 +10,12 @@ import * as modes from 'vs/editor/common/modes'; import { ICommonCodeEditor } from 'vs/editor/common/editorCommon'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { Schemas } from 'vs/base/common/network'; -import * as paths from 'vs/base/common/paths'; export class EditorModeContext extends Disposable { private _editor: ICommonCodeEditor; private _langId: IContextKey; - private _editorExtension: IContextKey; private _hasCompletionItemProvider: IContextKey; private _hasCodeActionsProvider: IContextKey; private _hasCodeLensProvider: IContextKey; @@ -42,7 +40,6 @@ export class EditorModeContext extends Disposable { this._editor = editor; this._langId = EditorContextKeys.languageId.bindTo(contextKeyService); - this._editorExtension = EditorContextKeys.editorExtension.bindTo(contextKeyService); this._hasCompletionItemProvider = EditorContextKeys.hasCompletionItemProvider.bindTo(contextKeyService); this._hasCodeActionsProvider = EditorContextKeys.hasCodeActionsProvider.bindTo(contextKeyService); this._hasCodeLensProvider = EditorContextKeys.hasCodeLensProvider.bindTo(contextKeyService); @@ -90,7 +87,6 @@ export class EditorModeContext extends Disposable { reset() { this._langId.reset(); - this._editorExtension.reset(); this._hasCompletionItemProvider.reset(); this._hasCodeActionsProvider.reset(); this._hasCodeLensProvider.reset(); @@ -115,7 +111,6 @@ export class EditorModeContext extends Disposable { return; } this._langId.set(model.getLanguageIdentifier().language); - this._editorExtension.set(paths.extname(model.uri.fsPath)); this._hasCompletionItemProvider.set(modes.SuggestRegistry.has(model)); this._hasCodeActionsProvider.set(modes.CodeActionProviderRegistry.has(model)); this._hasCodeLensProvider.set(modes.CodeLensProviderRegistry.has(model)); diff --git a/src/vs/workbench/common/resources.ts b/src/vs/workbench/common/resources.ts index 67857f78e7c..ec82d07b99b 100644 --- a/src/vs/workbench/common/resources.ts +++ b/src/vs/workbench/common/resources.ts @@ -23,7 +23,7 @@ export class ResourceContextKey implements IContextKey { static Filename = new RawContextKey('resourceFilename', undefined); static LangId = new RawContextKey('resourceLangId', undefined); static Resource = new RawContextKey('resource', undefined); - static Extension = new RawContextKey('resourceExtension', undefined); + static Extension = new RawContextKey('resourceExtname', undefined); private _resourceKey: IContextKey; private _schemeKey: IContextKey;