mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from vscode a348d103d1256a06a2c9b3f9b406298a9fef6898 (#15681)
* Merge from vscode a348d103d1256a06a2c9b3f9b406298a9fef6898 * Fixes and cleanup * Distro * Fix hygiene yarn * delete no yarn lock changes file * Fix hygiene * Fix layer check * Fix CI * Skip lib checks * Remove tests deleted in vs code * Fix tests * Distro * Fix tests and add removed extension point * Skip failing notebook tests for now * Disable broken tests and cleanup build folder * Update yarn.lock and fix smoke tests * Bump sqlite * fix contributed actions and file spacing * Fix user data path * Update yarn.locks Co-authored-by: ADS Merger <karlb@microsoft.com>
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, parse, visit } from 'jsonc-parser';
|
||||
import { getLocation, JSONPath, parse, visit } from 'jsonc-parser';
|
||||
import * as vscode from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { SettingsDocument } from './settingsDocumentHelper';
|
||||
@@ -22,6 +22,9 @@ export function activate(context: vscode.ExtensionContext): void {
|
||||
|
||||
// task.json variable suggestions
|
||||
context.subscriptions.push(registerVariableCompletions('**/tasks.json'));
|
||||
|
||||
// keybindings.json/package.json context key suggestions
|
||||
context.subscriptions.push(registerContextKeyCompletions());
|
||||
}
|
||||
|
||||
function registerSettingsCompletions(): vscode.Disposable {
|
||||
@@ -136,3 +139,83 @@ vscode.languages.registerDocumentSymbolProvider({ pattern: '**/launch.json', lan
|
||||
return result;
|
||||
}
|
||||
}, { label: 'Launch Targets' });
|
||||
|
||||
function registerContextKeyCompletions(): vscode.Disposable {
|
||||
type ContextKeyInfo = { key: string, type?: string, description?: string };
|
||||
|
||||
const paths = new Map<vscode.DocumentFilter, JSONPath[]>([
|
||||
[{ language: 'jsonc', pattern: '**/keybindings.json' }, [
|
||||
['*', 'when']
|
||||
]],
|
||||
[{ language: 'json', pattern: '**/package.json' }, [
|
||||
['contributes', 'menus', '*', '*', 'when'],
|
||||
['contributes', 'views', '*', '*', 'when'],
|
||||
['contributes', 'viewsWelcome', '*', 'when'],
|
||||
['contributes', 'keybindings', '*', 'when'],
|
||||
['contributes', 'keybindings', 'when'],
|
||||
]]
|
||||
]);
|
||||
|
||||
return vscode.languages.registerCompletionItemProvider(
|
||||
[...paths.keys()],
|
||||
{
|
||||
async provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken) {
|
||||
|
||||
const location = getLocation(document.getText(), document.offsetAt(position));
|
||||
|
||||
if (location.isAtPropertyKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
let isValidLocation = false;
|
||||
for (const [key, value] of paths) {
|
||||
if (vscode.languages.match(key, document)) {
|
||||
if (value.some(location.matches.bind(location))) {
|
||||
isValidLocation = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isValidLocation) {
|
||||
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 inserting = replacing.with(undefined, position);
|
||||
|
||||
const data = await vscode.commands.executeCommand<ContextKeyInfo[]>('getContextKeyInfo');
|
||||
if (token.isCancellationRequested || !data) {
|
||||
return;
|
||||
}
|
||||
|
||||
const result = new vscode.CompletionList();
|
||||
for (const item of data) {
|
||||
const completion = new vscode.CompletionItem(item.key, vscode.CompletionItemKind.Constant);
|
||||
completion.detail = item.type;
|
||||
completion.range = { replacing, inserting };
|
||||
completion.documentation = item.description;
|
||||
result.items.push(completion);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -33,3 +33,28 @@ export function provideInstalledExtensionProposals(existing: string[], additiona
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function provideWorkspaceTrustExtensionProposals(existing: string[], range: vscode.Range): vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList> {
|
||||
if (Array.isArray(existing)) {
|
||||
const extensions = vscode.extensions.all.filter(e => e.packageJSON.main);
|
||||
const extensionProposals = extensions.filter(e => existing.indexOf(e.id) === -1);
|
||||
if (extensionProposals.length) {
|
||||
return extensionProposals.map(e => {
|
||||
const item = new vscode.CompletionItem(e.id);
|
||||
const insertText = `"${e.id}": {\n\t"supported": false,\n\t"version": "${e.packageJSON.version}"\n}`;
|
||||
item.kind = vscode.CompletionItemKind.Value;
|
||||
item.insertText = insertText;
|
||||
item.range = range;
|
||||
item.filterText = insertText;
|
||||
return item;
|
||||
});
|
||||
} else {
|
||||
const example = new vscode.CompletionItem(localize('exampleExtension', "Example"));
|
||||
example.insertText = '"vscode.csharp: {\n\t"supported": false,\n\t"version": "0.0.0"\n}`;"';
|
||||
example.kind = vscode.CompletionItemKind.Value;
|
||||
example.range = range;
|
||||
return [example];
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { getLocation, Location, parse } from 'jsonc-parser';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { provideInstalledExtensionProposals } from './extensionsProposals';
|
||||
import { provideInstalledExtensionProposals, provideWorkspaceTrustExtensionProposals } from './extensionsProposals';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
@@ -60,6 +60,15 @@ export class SettingsDocument {
|
||||
return provideInstalledExtensionProposals(alreadyConfigured, `: [\n\t"ui"\n]`, range, true);
|
||||
}
|
||||
|
||||
// extensions.supportUntrustedWorkspaces
|
||||
if (location.path[0] === 'extensions.supportUntrustedWorkspaces' && location.path.length === 2 && location.isAtPropertyKey) {
|
||||
let alreadyConfigured: string[] = [];
|
||||
try {
|
||||
alreadyConfigured = Object.keys(parse(this.document.getText())['extensions.supportUntrustedWorkspaces']);
|
||||
} catch (e) {/* ignore error */ }
|
||||
return provideWorkspaceTrustExtensionProposals(alreadyConfigured, range);
|
||||
}
|
||||
|
||||
return this.provideLanguageOverridesCompletionItems(location, position);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user