mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Merge from vscode merge-base (#22780)
* Revert "Revert "Merge from vscode merge-base (#22769)" (#22779)"
This reverts commit 47a1745180.
* Fix notebook download task
* Remove done call from extensions-ci
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { getLocation, JSONPath, parse, visit } from 'jsonc-parser';
|
||||
import { getLocation, JSONPath, parse, visit, Location } from 'jsonc-parser';
|
||||
import * as vscode from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { SettingsDocument } from './settingsDocumentHelper';
|
||||
@@ -39,9 +39,11 @@ function registerVariableCompletions(pattern: string): vscode.Disposable {
|
||||
return vscode.languages.registerCompletionItemProvider({ language: 'jsonc', pattern }, {
|
||||
provideCompletionItems(document, position, _token) {
|
||||
const location = getLocation(document.getText(), document.offsetAt(position));
|
||||
if (!location.isAtPropertyKey && location.previousNode && location.previousNode.type === 'string') {
|
||||
const indexOf$ = document.lineAt(position.line).text.lastIndexOf('$', position.character);
|
||||
const startPosition = indexOf$ >= 0 ? new vscode.Position(position.line, indexOf$) : position;
|
||||
if (isCompletingInsidePropertyStringValue(document, location, position)) {
|
||||
let range = document.getWordRangeAtPosition(position, /\$\{[^"\}]*\}?/);
|
||||
if (!range || range.start.isEqual(position) || range.end.isEqual(position) && document.getText(range).endsWith('}')) {
|
||||
range = new vscode.Range(position, position);
|
||||
}
|
||||
|
||||
return [
|
||||
{ label: 'workspaceFolder', detail: localize('workspaceFolder', "The path of the folder opened in VS Code") },
|
||||
@@ -61,7 +63,7 @@ function registerVariableCompletions(pattern: string): vscode.Disposable {
|
||||
{ label: 'extensionInstallFolder', detail: localize('extensionInstallFolder', "The path where an an extension is installed."), param: 'publisher.extension' },
|
||||
].map(variable => ({
|
||||
label: `\${${variable.label}}`,
|
||||
range: new vscode.Range(startPosition, position),
|
||||
range,
|
||||
insertText: variable.param ? new vscode.SnippetString(`\${${variable.label}:`).appendPlaceholder(variable.param).appendText('}') : (`\${${variable.label}}`),
|
||||
detail: variable.detail
|
||||
}));
|
||||
@@ -72,6 +74,18 @@ function registerVariableCompletions(pattern: string): vscode.Disposable {
|
||||
});
|
||||
}
|
||||
|
||||
function isCompletingInsidePropertyStringValue(document: vscode.TextDocument, location: Location, pos: vscode.Position) {
|
||||
if (location.isAtPropertyKey) {
|
||||
return false;
|
||||
}
|
||||
const previousNode = location.previousNode;
|
||||
if (previousNode && previousNode.type === 'string') {
|
||||
const offset = document.offsetAt(pos);
|
||||
return offset > previousNode.offset && offset < previousNode.offset + previousNode.length;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
interface IExtensionsContent {
|
||||
recommendations: string[];
|
||||
}
|
||||
@@ -84,8 +98,8 @@ function registerExtensionsCompletionsInExtensionsDocument(): vscode.Disposable
|
||||
return vscode.languages.registerCompletionItemProvider({ pattern: '**/extensions.json' }, {
|
||||
provideCompletionItems(document, position, _token) {
|
||||
const location = getLocation(document.getText(), document.offsetAt(position));
|
||||
const range = document.getWordRangeAtPosition(position) || new vscode.Range(position, position);
|
||||
if (location.path[0] === 'recommendations') {
|
||||
const range = getReplaceRange(document, location, position);
|
||||
const extensionsContent = <IExtensionsContent>parse(document.getText());
|
||||
return provideInstalledExtensionProposals(extensionsContent && extensionsContent.recommendations || [], '', range, false);
|
||||
}
|
||||
@@ -98,8 +112,8 @@ function registerExtensionsCompletionsInWorkspaceConfigurationDocument(): vscode
|
||||
return vscode.languages.registerCompletionItemProvider({ pattern: '**/*.code-workspace' }, {
|
||||
provideCompletionItems(document, position, _token) {
|
||||
const location = getLocation(document.getText(), document.offsetAt(position));
|
||||
const range = document.getWordRangeAtPosition(position) || new vscode.Range(position, position);
|
||||
if (location.path[0] === 'extensions' && location.path[1] === 'recommendations') {
|
||||
const range = getReplaceRange(document, location, position);
|
||||
const extensionsContent = <IExtensionsContent>parse(document.getText())['extensions'];
|
||||
return provideInstalledExtensionProposals(extensionsContent && extensionsContent.recommendations || [], '', range, false);
|
||||
}
|
||||
@@ -108,6 +122,17 @@ function registerExtensionsCompletionsInWorkspaceConfigurationDocument(): vscode
|
||||
});
|
||||
}
|
||||
|
||||
function getReplaceRange(document: vscode.TextDocument, location: Location, position: vscode.Position) {
|
||||
const node = location.previousNode;
|
||||
if (node) {
|
||||
const nodeStart = document.positionAt(node.offset), nodeEnd = document.positionAt(node.offset + node.length);
|
||||
if (nodeStart.isBeforeOrEqual(position) && nodeEnd.isAfterOrEqual(position)) {
|
||||
return new vscode.Range(nodeStart, nodeEnd);
|
||||
}
|
||||
}
|
||||
return new vscode.Range(position, position);
|
||||
}
|
||||
|
||||
vscode.languages.registerDocumentSymbolProvider({ pattern: '**/launch.json', language: 'jsonc' }, {
|
||||
provideDocumentSymbols(document: vscode.TextDocument, _token: vscode.CancellationToken): vscode.ProviderResult<vscode.SymbolInformation[]> {
|
||||
const result: vscode.SymbolInformation[] = [];
|
||||
@@ -180,28 +205,11 @@ function registerContextKeyCompletions(): vscode.Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
if (!isValidLocation) {
|
||||
if (!isValidLocation || !isCompletingInsidePropertyStringValue(document, location, position)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// for JSON everything with quotes is a word
|
||||
const jsonWord = document.getWordRangeAtPosition(position);
|
||||
if (!jsonWord || jsonWord.start.isEqual(position) || jsonWord.end.isEqual(position)) {
|
||||
// we aren't inside a "JSON word" or on its quotes
|
||||
return;
|
||||
}
|
||||
|
||||
let replacing: vscode.Range | undefined;
|
||||
if (jsonWord.end.character - jsonWord.start.character === 2 || document.getWordRangeAtPosition(position, /\s+/)) {
|
||||
// empty json word or on whitespace
|
||||
replacing = new vscode.Range(position, position);
|
||||
} else {
|
||||
replacing = document.getWordRangeAtPosition(position, /[a-zA-Z.]+/);
|
||||
}
|
||||
|
||||
if (!replacing) {
|
||||
return;
|
||||
}
|
||||
const replacing = document.getWordRangeAtPosition(position, /[a-zA-Z.]+/) || new vscode.Range(position, position);
|
||||
const inserting = replacing.with(undefined, position);
|
||||
|
||||
const data = await vscode.commands.executeCommand<ContextKeyInfo[]>('getContextKeyInfo');
|
||||
|
||||
Reference in New Issue
Block a user