mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
move window.title config helper out to extension (for #20049)
This commit is contained in:
parent
7c8d8e822f
commit
bcff7c60e5
|
@ -18,7 +18,8 @@
|
|||
"watch": "gulp watch-extension:configuration-editing"
|
||||
},
|
||||
"dependencies": {
|
||||
"jsonc-parser": "^0.3.1"
|
||||
"jsonc-parser": "^0.3.1",
|
||||
"vscode-nls": "^2.0.1"
|
||||
},
|
||||
"contributes": {
|
||||
"jsonValidation": [
|
||||
|
|
|
@ -8,16 +8,22 @@
|
|||
import * as vscode from 'vscode';
|
||||
import { getLocation, visit } from 'jsonc-parser';
|
||||
import * as path from 'path';
|
||||
import * as nls from 'vscode-nls';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
const decoration = vscode.window.createTextEditorDecorationType({
|
||||
color: '#b1b1b1'
|
||||
});
|
||||
|
||||
export function activate(context) {
|
||||
export function activate(context): void {
|
||||
|
||||
//keybindings.json command-suggestions
|
||||
context.subscriptions.push(registerKeybindingsCompletions());
|
||||
|
||||
//settings.json suggestions
|
||||
context.subscriptions.push(registerSettingsCompletions());
|
||||
|
||||
// launch.json decorations
|
||||
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(editor => updateLaunchJsonDecorations(editor), null, context.subscriptions));
|
||||
context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(event => {
|
||||
|
@ -38,23 +44,50 @@ function registerKeybindingsCompletions(): vscode.Disposable {
|
|||
if (location.path[1] === 'command') {
|
||||
|
||||
const range = document.getWordRangeAtPosition(position) || new vscode.Range(position, position);
|
||||
return commands.then(ids => ids.map(id => newCompletionItem(id, range)));
|
||||
return commands.then(ids => ids.map(id => newCompletionItem(JSON.stringify(id), range)));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function newCompletionItem(text: string, range: vscode.Range) {
|
||||
const item = new vscode.CompletionItem(JSON.stringify(text));
|
||||
function registerSettingsCompletions(): vscode.Disposable {
|
||||
return vscode.languages.registerCompletionItemProvider({ language: 'json', pattern: '**/settings.json' }, {
|
||||
|
||||
provideCompletionItems(document, position, token) {
|
||||
const completions: vscode.CompletionItem[] = [];
|
||||
const location = getLocation(document.getText(), document.offsetAt(position));
|
||||
|
||||
// window.title
|
||||
if (location.path[0] === 'window.title') {
|
||||
const range = document.getWordRangeAtPosition(position) || new vscode.Range(position, position);
|
||||
|
||||
completions.push(newCompletionItem('${activeEditorName}', range, localize('activeEditorName', "e.g. myFile.txt")));
|
||||
completions.push(newCompletionItem('${activeFilePath}', range, localize('activeFilePath', "e.g. /Users/Development/myProject/myFile.txt")));
|
||||
completions.push(newCompletionItem('${rootName}', range, localize('rootName', "e.g. myProject")));
|
||||
completions.push(newCompletionItem('${rootPath}', range, localize('rootPath', "e.g. /Users/Development/myProject")));
|
||||
completions.push(newCompletionItem('${appName}', range, localize('appName', "e.g. VS Code")));
|
||||
completions.push(newCompletionItem('${dirty}', range, localize('dirty', "a dirty indicator if the active editor is dirty")));
|
||||
completions.push(newCompletionItem('${separator}', range, localize('separator', "a conditional separator (' - ') that only shows when surrounded by variables with values")));
|
||||
}
|
||||
|
||||
return Promise.resolve(completions);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function newCompletionItem(text: string, range: vscode.Range, description?: string): vscode.CompletionItem {
|
||||
const item = new vscode.CompletionItem(text);
|
||||
item.kind = vscode.CompletionItemKind.Value;
|
||||
item.detail = description;
|
||||
item.textEdit = {
|
||||
range,
|
||||
newText: item.label
|
||||
};
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
function updateLaunchJsonDecorations(editor: vscode.TextEditor | undefined) {
|
||||
function updateLaunchJsonDecorations(editor: vscode.TextEditor | undefined): void {
|
||||
if (!editor || path.basename(editor.document.fileName) !== 'launch.json') {
|
||||
return;
|
||||
}
|
||||
|
@ -85,5 +118,4 @@ function updateLaunchJsonDecorations(editor: vscode.TextEditor | undefined) {
|
|||
});
|
||||
|
||||
editor.setDecorations(decoration, ranges);
|
||||
}
|
||||
|
||||
}
|
|
@ -19,7 +19,6 @@ import Strings = require('./utils/strings');
|
|||
import { JSONDocument, JSONSchema, LanguageSettings, getLanguageService } from 'vscode-json-languageservice';
|
||||
import { ProjectJSONContribution } from './jsoncontributions/projectJSONContribution';
|
||||
import { GlobPatternContribution } from './jsoncontributions/globPatternContribution';
|
||||
import { WindowTitleContribution } from './jsoncontributions/windowTitleContribution';
|
||||
import { FileAssociationContribution } from './jsoncontributions/fileAssociationContribution';
|
||||
import { getLanguageModelCache } from './languageModelCache';
|
||||
|
||||
|
@ -129,7 +128,6 @@ let languageService = getLanguageService({
|
|||
contributions: [
|
||||
new ProjectJSONContribution(),
|
||||
new GlobPatternContribution(),
|
||||
new WindowTitleContribution(),
|
||||
filesAssociationContribution
|
||||
]
|
||||
});
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { MarkedString } from 'vscode-languageserver';
|
||||
import Strings = require('../utils/strings');
|
||||
import { JSONWorkerContribution, JSONPath, CompletionsCollector } from 'vscode-json-languageservice';
|
||||
|
||||
import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
export class WindowTitleContribution implements JSONWorkerContribution {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
private isSettingsFile(resource: string): boolean {
|
||||
return Strings.endsWith(resource, '/settings.json');
|
||||
}
|
||||
|
||||
public collectDefaultCompletions(resource: string, result: CompletionsCollector): Thenable<any> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public collectPropertyCompletions(resource: string, location: JSONPath, currentWord: string, addValue: boolean, isLast: boolean, result: CompletionsCollector): Thenable<any> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public collectValueCompletions(resource: string, location: JSONPath, currentKey: string, result: CompletionsCollector): Thenable<any> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public getInfoContribution(resource: string, location: JSONPath): Thenable<MarkedString[]> {
|
||||
if (this.isSettingsFile(resource) && location.length === 1 && location[0] === 'window.title') {
|
||||
return Promise.resolve([
|
||||
MarkedString.fromPlainText(localize('windowTitle.description', "Controls the window title based on the active editor. Variables are substituted based on the context:")),
|
||||
MarkedString.fromPlainText(localize('windowTitle.activeEditorName', "${activeEditorName}: e.g. myFile.txt")),
|
||||
MarkedString.fromPlainText(localize('windowTitle.activeFilePath', "${activeFilePath}: e.g. /Users/Development/myProject/myFile.txt")),
|
||||
MarkedString.fromPlainText(localize('windowTitle.rootName', "${rootName}: e.g. myProject")),
|
||||
MarkedString.fromPlainText(localize('windowTitle.rootPath', "${rootPath}: e.g. /Users/Development/myProject")),
|
||||
MarkedString.fromPlainText(localize('windowTitle.appName', "${appName}: e.g. VS Code")),
|
||||
MarkedString.fromPlainText(localize('windowTitle.dirty', "${dirty}: a dirty indicator if the active editor is dirty")),
|
||||
MarkedString.fromPlainText(localize('windowTitle.separator', "${separator}: a conditional separator (\" - \") that only shows when surrounded by variables with values"))
|
||||
]);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue