Setup basic typescript.isManagedFile context
This commit is contained in:
parent
04c4491a43
commit
7c13230aff
4 changed files with 62 additions and 8 deletions
|
@ -483,23 +483,23 @@
|
|||
"commandPalette": [
|
||||
{
|
||||
"command": "typescript.reloadProjects",
|
||||
"when": "editorLangId == 'typescript'"
|
||||
"when": "editorLangId == typescript && typescript.isManagedFile"
|
||||
},
|
||||
{
|
||||
"command": "typescript.reloadProjects",
|
||||
"when": "editorLangId == typescriptreact"
|
||||
"when": "editorLangId == typescriptreact && typescript.isManagedFile"
|
||||
},
|
||||
{
|
||||
"command": "javascript.reloadProjects",
|
||||
"when": "editorLangId == 'javascript'"
|
||||
"when": "editorLangId == javascript && typescript.isManagedFile"
|
||||
},
|
||||
{
|
||||
"command": "javascript.reloadProjects",
|
||||
"when": "editorLangId == javascriptreact"
|
||||
"when": "editorLangId == javascriptreact && typescript.isManagedFile"
|
||||
},
|
||||
{
|
||||
"command": "typescript.goToProjectConfig",
|
||||
"when": "editorLangId == 'typescript'"
|
||||
"when": "editorLangId == typescript && typescript.isManagedFile"
|
||||
},
|
||||
{
|
||||
"command": "typescript.goToProjectConfig",
|
||||
|
@ -507,11 +507,11 @@
|
|||
},
|
||||
{
|
||||
"command": "javascript.goToProjectConfig",
|
||||
"when": "editorLangId == 'javascript'"
|
||||
"when": "editorLangId == javascript && typescript.isManagedFile"
|
||||
},
|
||||
{
|
||||
"command": "javascript.goToProjectConfig",
|
||||
"when": "editorLangId == javascriptreact"
|
||||
"when": "editorLangId == javascriptreact && typescript.isManagedFile"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -14,6 +14,7 @@ import * as ProjectStatus from './utils/projectStatus';
|
|||
import * as languageModeIds from './utils/languageModeIds';
|
||||
import * as languageConfigurations from './utils/languageConfigurations';
|
||||
import { standardLanguageDescriptions } from './utils/languageDescription';
|
||||
import ManagedFileContextManager from './utils/managedFileContext';
|
||||
|
||||
export function activate(
|
||||
context: vscode.ExtensionContext
|
||||
|
@ -25,10 +26,12 @@ export function activate(
|
|||
|
||||
const lazyClientHost = createLazyClientHost(context, plugins, commandManager);
|
||||
|
||||
context.subscriptions.push(new ManagedFileContextManager(resource => lazyClientHost().serviceClient.normalizePath(resource)));
|
||||
registerCommands(commandManager, lazyClientHost);
|
||||
context.subscriptions.push(new TypeScriptTaskProviderManager(() => lazyClientHost().serviceClient));
|
||||
context.subscriptions.push(vscode.languages.setLanguageConfiguration(languageModeIds.jsxTags, languageConfigurations.jsxTags));
|
||||
|
||||
|
||||
const supportedLanguage = [].concat.apply([], standardLanguageDescriptions.map(x => x.modeIds).concat(plugins.map(x => x.languages)));
|
||||
function didOpenTextDocument(textDocument: vscode.TextDocument): boolean {
|
||||
if (supportedLanguage.indexOf(textDocument.languageId) >= 0) {
|
||||
|
|
|
@ -235,7 +235,7 @@ class TscTaskProvider implements vscode.TaskProvider {
|
|||
}
|
||||
|
||||
/**
|
||||
* Manages registrations of TypeScript task provides with VScode.
|
||||
* Manages registrations of TypeScript task providers with VS Code.
|
||||
*/
|
||||
export default class TypeScriptTaskProviderManager {
|
||||
private taskProviderSub: vscode.Disposable | undefined = undefined;
|
||||
|
|
51
extensions/typescript/src/utils/managedFileContext.ts
Normal file
51
extensions/typescript/src/utils/managedFileContext.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as languageModeIds from './languageModeIds';
|
||||
|
||||
/**
|
||||
* When clause context set when the current file is managed by vscode's built-in typescript extension.
|
||||
*/
|
||||
const isManagedFile_contextName = 'typescript.isManagedFile';
|
||||
|
||||
export default class ManagedFileContextManager {
|
||||
|
||||
private isInManagedFileContext: boolean = false;
|
||||
|
||||
private readonly onDidChangeActiveTextEditorSub: vscode.Disposable;
|
||||
|
||||
public constructor(
|
||||
private readonly normalizePath: (resource: vscode.Uri) => string | null
|
||||
) {
|
||||
this.onDidChangeActiveTextEditorSub = vscode.window.onDidChangeActiveTextEditor(this.onDidChangeActiveTextEditor, this);
|
||||
|
||||
if (vscode.window.activeTextEditor) {
|
||||
this.onDidChangeActiveTextEditor(vscode.window.activeTextEditor);
|
||||
}
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
this.onDidChangeActiveTextEditorSub.dispose();
|
||||
}
|
||||
|
||||
private onDidChangeActiveTextEditor(editor: vscode.TextEditor): any {
|
||||
const isManagedFile = isSupportedLanguageMode(editor.document) && this.normalizePath(editor.document.uri) !== null;
|
||||
this.updateContext(isManagedFile);
|
||||
}
|
||||
|
||||
private updateContext(newValue: boolean) {
|
||||
if (newValue === this.isInManagedFileContext) {
|
||||
return;
|
||||
}
|
||||
|
||||
vscode.commands.executeCommand('setContext', isManagedFile_contextName, newValue);
|
||||
this.isInManagedFileContext = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
function isSupportedLanguageMode(doc: vscode.TextDocument) {
|
||||
return vscode.languages.match([languageModeIds.typescript, languageModeIds.typescriptreact, languageModeIds.javascript, languageModeIds.javascript], doc) > 0;
|
||||
}
|
Loading…
Reference in a new issue