Skip to content

Commit bcff7c6

Browse files
committed
move window.title config helper out to extension (for microsoft#20049)
1 parent 7c8d8e8 commit bcff7c6

File tree

4 files changed

+41
-61
lines changed

4 files changed

+41
-61
lines changed

extensions/configuration-editing/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"watch": "gulp watch-extension:configuration-editing"
1919
},
2020
"dependencies": {
21-
"jsonc-parser": "^0.3.1"
21+
"jsonc-parser": "^0.3.1",
22+
"vscode-nls": "^2.0.1"
2223
},
2324
"contributes": {
2425
"jsonValidation": [

extensions/configuration-editing/src/extension.ts

+39-7
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@
88
import * as vscode from 'vscode';
99
import { getLocation, visit } from 'jsonc-parser';
1010
import * as path from 'path';
11+
import * as nls from 'vscode-nls';
12+
13+
const localize = nls.loadMessageBundle();
1114

1215
const decoration = vscode.window.createTextEditorDecorationType({
1316
color: '#b1b1b1'
1417
});
1518

16-
export function activate(context) {
19+
export function activate(context): void {
1720

1821
//keybindings.json command-suggestions
1922
context.subscriptions.push(registerKeybindingsCompletions());
2023

24+
//settings.json suggestions
25+
context.subscriptions.push(registerSettingsCompletions());
26+
2127
// launch.json decorations
2228
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(editor => updateLaunchJsonDecorations(editor), null, context.subscriptions));
2329
context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(event => {
@@ -38,23 +44,50 @@ function registerKeybindingsCompletions(): vscode.Disposable {
3844
if (location.path[1] === 'command') {
3945

4046
const range = document.getWordRangeAtPosition(position) || new vscode.Range(position, position);
41-
return commands.then(ids => ids.map(id => newCompletionItem(id, range)));
47+
return commands.then(ids => ids.map(id => newCompletionItem(JSON.stringify(id), range)));
4248
}
4349
}
4450
});
4551
}
4652

47-
function newCompletionItem(text: string, range: vscode.Range) {
48-
const item = new vscode.CompletionItem(JSON.stringify(text));
53+
function registerSettingsCompletions(): vscode.Disposable {
54+
return vscode.languages.registerCompletionItemProvider({ language: 'json', pattern: '**/settings.json' }, {
55+
56+
provideCompletionItems(document, position, token) {
57+
const completions: vscode.CompletionItem[] = [];
58+
const location = getLocation(document.getText(), document.offsetAt(position));
59+
60+
// window.title
61+
if (location.path[0] === 'window.title') {
62+
const range = document.getWordRangeAtPosition(position) || new vscode.Range(position, position);
63+
64+
completions.push(newCompletionItem('${activeEditorName}', range, localize('activeEditorName', "e.g. myFile.txt")));
65+
completions.push(newCompletionItem('${activeFilePath}', range, localize('activeFilePath', "e.g. /Users/Development/myProject/myFile.txt")));
66+
completions.push(newCompletionItem('${rootName}', range, localize('rootName', "e.g. myProject")));
67+
completions.push(newCompletionItem('${rootPath}', range, localize('rootPath', "e.g. /Users/Development/myProject")));
68+
completions.push(newCompletionItem('${appName}', range, localize('appName', "e.g. VS Code")));
69+
completions.push(newCompletionItem('${dirty}', range, localize('dirty', "a dirty indicator if the active editor is dirty")));
70+
completions.push(newCompletionItem('${separator}', range, localize('separator', "a conditional separator (' - ') that only shows when surrounded by variables with values")));
71+
}
72+
73+
return Promise.resolve(completions);
74+
}
75+
});
76+
}
77+
78+
function newCompletionItem(text: string, range: vscode.Range, description?: string): vscode.CompletionItem {
79+
const item = new vscode.CompletionItem(text);
4980
item.kind = vscode.CompletionItemKind.Value;
81+
item.detail = description;
5082
item.textEdit = {
5183
range,
5284
newText: item.label
5385
};
86+
5487
return item;
5588
}
5689

57-
function updateLaunchJsonDecorations(editor: vscode.TextEditor | undefined) {
90+
function updateLaunchJsonDecorations(editor: vscode.TextEditor | undefined): void {
5891
if (!editor || path.basename(editor.document.fileName) !== 'launch.json') {
5992
return;
6093
}
@@ -85,5 +118,4 @@ function updateLaunchJsonDecorations(editor: vscode.TextEditor | undefined) {
85118
});
86119

87120
editor.setDecorations(decoration, ranges);
88-
}
89-
121+
}

extensions/json/server/src/jsonServerMain.ts

-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import Strings = require('./utils/strings');
1919
import { JSONDocument, JSONSchema, LanguageSettings, getLanguageService } from 'vscode-json-languageservice';
2020
import { ProjectJSONContribution } from './jsoncontributions/projectJSONContribution';
2121
import { GlobPatternContribution } from './jsoncontributions/globPatternContribution';
22-
import { WindowTitleContribution } from './jsoncontributions/windowTitleContribution';
2322
import { FileAssociationContribution } from './jsoncontributions/fileAssociationContribution';
2423
import { getLanguageModelCache } from './languageModelCache';
2524

@@ -129,7 +128,6 @@ let languageService = getLanguageService({
129128
contributions: [
130129
new ProjectJSONContribution(),
131130
new GlobPatternContribution(),
132-
new WindowTitleContribution(),
133131
filesAssociationContribution
134132
]
135133
});

extensions/json/server/src/jsoncontributions/windowTitleContribution.ts

-51
This file was deleted.

0 commit comments

Comments
 (0)