Merge from vscode a416c77e56ef0314ae00633faa04878151610de8 (#8600)

* Merge from vscode a416c77e56ef0314ae00633faa04878151610de8

* distro

* fix tests

* fix tests
This commit is contained in:
Anthony Dresser
2019-12-07 17:19:16 -08:00
committed by GitHub
parent a7ff238653
commit d614116b63
155 changed files with 1982 additions and 1599 deletions

View File

@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/schema#",
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Configures an attached to container",
"allowComments": true,
"type": "object",
@@ -18,6 +18,10 @@
"type": "integer"
}
},
"settings": {
"$ref": "vscode://schemas/settings/machine",
"description": "Machine specific settings that should be copied into the container."
},
"remoteEnv": {
"type": "object",
"additionalProperties": {

View File

@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/schema#",
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Defines a dev container",
"allowComments": true,
"type": "object",
@@ -84,6 +84,13 @@
"type": "boolean",
"description": "Controls whether on Linux the container's user should be updated with the local user's UID and GID. On by default."
},
"mounts": {
"type": "array",
"description": "Mount points to set up when creating the container. See Docker's documentation for the --mount option for the supported syntax.",
"items": {
"type": "string"
}
},
"runArgs": {
"type": "array",
"description": "The arguments required when starting in the container.",

View File

@@ -13,5 +13,4 @@ Supported image formats:
- `*.bmp`
- `*.gif`
- `*.ico`
- `*.tga`
- `*.webp`

View File

@@ -2,7 +2,7 @@
"name": "image-preview",
"displayName": "%displayName%",
"description": "%description%",
"extensionKind": "ui",
"extensionKind": ["ui", "workspace"],
"version": "1.0.0",
"publisher": "vscode",
"icon": "icon.png",

View File

@@ -10,8 +10,16 @@ import { xhr, XHRResponse, getErrorStatusDescription } from 'request-light';
const localize = nls.loadMessageBundle();
import { workspace, window, languages, commands, ExtensionContext, extensions, Uri, LanguageConfiguration, Diagnostic, StatusBarAlignment, TextEditor, TextDocument, FormattingOptions, CancellationToken, ProviderResult, TextEdit, Range, Disposable } from 'vscode';
import { LanguageClient, LanguageClientOptions, RequestType, ServerOptions, TransportKind, NotificationType, DidChangeConfigurationNotification, HandleDiagnosticsSignature, ResponseError, DocumentRangeFormattingParams, DocumentRangeFormattingRequest } from 'vscode-languageclient';
import {
workspace, window, languages, commands, ExtensionContext, extensions, Uri, LanguageConfiguration,
Diagnostic, StatusBarAlignment, TextEditor, TextDocument, FormattingOptions, CancellationToken,
ProviderResult, TextEdit, Range, Position, Disposable, CompletionItem, CompletionList, CompletionContext
} from 'vscode';
import {
LanguageClient, LanguageClientOptions, RequestType, ServerOptions, TransportKind, NotificationType,
DidChangeConfigurationNotification, HandleDiagnosticsSignature, ResponseError, DocumentRangeFormattingParams,
DocumentRangeFormattingRequest, ProvideCompletionItemsSignature
} from 'vscode-languageclient';
import TelemetryReporter from 'vscode-extension-telemetry';
import { hash } from './utils/hash';
@@ -36,6 +44,10 @@ namespace SchemaAssociationNotification {
export const type: NotificationType<ISchemaAssociations, any> = new NotificationType('json/schemaAssociations');
}
namespace ResultLimitReachedNotification {
export const type: NotificationType<string, any> = new NotificationType('json/resultLimitReached');
}
interface IPackageInfo {
name: string;
version: string;
@@ -132,6 +144,29 @@ export function activate(context: ExtensionContext) {
}
next(uri, diagnostics);
},
// testing the replace / insert mode
provideCompletionItem(document: TextDocument, position: Position, context: CompletionContext, token: CancellationToken, next: ProvideCompletionItemsSignature): ProviderResult<CompletionItem[] | CompletionList> {
function updateRanges(item: CompletionItem) {
const range = item.range;
if (range && range.end.isAfter(position) && range.start.isBeforeOrEqual(position)) {
item.range2 = { inserting: new Range(range.start, position), replacing: range };
item.range = undefined;
}
}
function updateProposals(r: CompletionItem[] | CompletionList | null | undefined): CompletionItem[] | CompletionList | null | undefined {
if (r) {
(Array.isArray(r) ? r : r.items).forEach(updateRanges);
}
return r;
}
const isThenable = <T>(obj: ProviderResult<T>): obj is Thenable<T> => obj && (<any>obj)['then'];
const r = next(document, position, context, token);
if (isThenable<CompletionItem[] | CompletionList | null | undefined>(r)) {
return r.then(updateProposals);
}
return updateProposals(r);
}
}
};
@@ -239,6 +274,12 @@ export function activate(context: ExtensionContext) {
updateFormatterRegistration();
toDispose.push({ dispose: () => rangeFormatting && rangeFormatting.dispose() });
toDispose.push(workspace.onDidChangeConfiguration(e => e.affectsConfiguration('html.format.enable') && updateFormatterRegistration()));
client.onNotification(ResultLimitReachedNotification.type, message => {
window.showInformationMessage(`${message}\nUse setting 'json.maxItemsComputed' to configure the limit.`);
});
});
let languageConfiguration: LanguageConfiguration = {
@@ -320,6 +361,8 @@ function getSchemaAssociation(_context: ExtensionContext): ISchemaAssociations {
function getSettings(): Settings {
let httpSettings = workspace.getConfiguration('http');
let resultLimit: number = Math.trunc(Math.max(0, Number(workspace.getConfiguration().get('json.maxItemsComputed')))) || 5000;
let settings: Settings = {
http: {
proxy: httpSettings.get('proxy'),
@@ -327,7 +370,7 @@ function getSettings(): Settings {
},
json: {
schemas: [],
resultLimit: 5000
resultLimit
}
};
let schemaSettingsById: { [schemaId: string]: JSONSchemaSettings } = Object.create(null);
@@ -422,5 +465,4 @@ function readJSONFile(location: string) {
console.log(`Problems reading ${location}: ${e}`);
return {};
}
}

View File

@@ -1,113 +1,125 @@
{
"name": "json-language-features",
"displayName": "%displayName%",
"description": "%description%",
"version": "1.0.0",
"publisher": "vscode",
"license": "MIT",
"aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
"engines": {
"vscode": "0.10.x"
},
"icon": "icons/json.png",
"activationEvents": [
"onLanguage:json",
"onLanguage:jsonc"
],
"main": "./client/out/jsonMain",
"enableProposedApi": true,
"scripts": {
"compile": "gulp compile-extension:json-language-features-client compile-extension:json-language-features-server",
"watch": "gulp watch-extension:json-language-features-client watch-extension:json-language-features-server",
"postinstall": "cd server && yarn install",
"install-client-next": "yarn add vscode-languageclient@next"
},
"categories": [
"Programming Languages"
],
"contributes": {
"configuration": {
"id": "json",
"order": 20,
"type": "object",
"title": "JSON",
"properties": {
"json.schemas": {
"type": "array",
"scope": "resource",
"description": "%json.schemas.desc%",
"items": {
"type": "object",
"default": {
"fileMatch": [
"/myfile"
],
"url": "schemaURL"
},
"properties": {
"url": {
"type": "string",
"default": "/user.schema.json",
"description": "%json.schemas.url.desc%"
},
"fileMatch": {
"type": "array",
"items": {
"type": "string",
"default": "MyFile.json",
"description": "%json.schemas.fileMatch.item.desc%"
},
"minItems": 1,
"description": "%json.schemas.fileMatch.desc%"
},
"schema": {
"$ref": "http://json-schema.org/draft-07/schema#",
"description": "%json.schemas.schema.desc%"
}
}
}
},
"json.format.enable": {
"type": "boolean",
"scope": "window",
"default": true,
"description": "%json.format.enable.desc%"
},
"json.trace.server": {
"type": "string",
"scope": "window",
"enum": [
"off",
"messages",
"verbose"
],
"default": "off",
"description": "%json.tracing.desc%"
},
"json.colorDecorators.enable": {
"type": "boolean",
"scope": "window",
"default": true,
"description": "%json.colorDecorators.enable.desc%",
"deprecationMessage": "%json.colorDecorators.enable.deprecationMessage%"
}
}
"name": "json-language-features",
"displayName": "%displayName%",
"description": "%description%",
"version": "1.0.0",
"publisher": "vscode",
"license": "MIT",
"aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
"engines": {
"vscode": "0.10.x"
},
"configurationDefaults": {
"[json]": {
"editor.quickSuggestions": {
"strings": true
"icon": "icons/json.png",
"activationEvents": [
"onLanguage:json",
"onLanguage:jsonc"
],
"main": "./client/out/jsonMain",
"enableProposedApi": true,
"scripts": {
"compile": "gulp compile-extension:json-language-features-client compile-extension:json-language-features-server",
"watch": "gulp watch-extension:json-language-features-client watch-extension:json-language-features-server",
"postinstall": "cd server && yarn install",
"install-client-next": "yarn add vscode-languageclient@next"
},
"categories": [
"Programming Languages"
],
"contributes": {
"configuration": {
"id": "json",
"order": 20,
"type": "object",
"title": "JSON",
"properties": {
"json.schemas": {
"type": "array",
"scope": "resource",
"description": "%json.schemas.desc%",
"items": {
"type": "object",
"default": {
"fileMatch": [
"/myfile"
],
"url": "schemaURL"
},
"properties": {
"url": {
"type": "string",
"default": "/user.schema.json",
"description": "%json.schemas.url.desc%"
},
"fileMatch": {
"type": "array",
"items": {
"type": "string",
"default": "MyFile.json",
"description": "%json.schemas.fileMatch.item.desc%"
},
"minItems": 1,
"description": "%json.schemas.fileMatch.desc%"
},
"schema": {
"$ref": "http://json-schema.org/draft-07/schema#",
"description": "%json.schemas.schema.desc%"
}
}
}
},
"json.format.enable": {
"type": "boolean",
"scope": "window",
"default": true,
"description": "%json.format.enable.desc%"
},
"json.trace.server": {
"type": "string",
"scope": "window",
"enum": [
"off",
"messages",
"verbose"
],
"default": "off",
"description": "%json.tracing.desc%"
},
"json.colorDecorators.enable": {
"type": "boolean",
"scope": "window",
"default": true,
"description": "%json.colorDecorators.enable.desc%",
"deprecationMessage": "%json.colorDecorators.enable.deprecationMessage%"
},
"json.maxItemsComputed": {
"type": "number",
"default": 5000,
"description": "%json.maxItemsComputed.desc%"
}
}
},
"configurationDefaults": {
"[json]": {
"editor.quickSuggestions": {
"strings": true
},
"editor.suggest.insertMode": "replace"
},
"[jsonc]": {
"editor.quickSuggestions": {
"strings": true
},
"editor.suggest.insertMode": "replace"
}
}
}
},
"dependencies": {
"request-light": "^0.2.5",
"vscode-extension-telemetry": "0.1.1",
"vscode-languageclient": "^6.0.0-next.3",
"vscode-nls": "^4.1.1"
},
"devDependencies": {
"@types/node": "^12.11.7"
}
},
"dependencies": {
"request-light": "^0.2.5",
"vscode-extension-telemetry": "0.1.1",
"vscode-languageclient": "^6.0.0-next.3",
"vscode-nls": "^4.1.1"
},
"devDependencies": {
"@types/node": "^12.11.7"
}
}

View File

@@ -11,5 +11,6 @@
"json.colorDecorators.enable.desc": "Enables or disables color decorators",
"json.colorDecorators.enable.deprecationMessage": "The setting `json.colorDecorators.enable` has been deprecated in favor of `editor.colorDecorators`.",
"json.schemaResolutionErrorMessage": "Unable to resolve schema.",
"json.clickToRetry": "Click to retry."
"json.clickToRetry": "Click to retry.",
"json.maxItemsComputed.desc": "The maximum number of outline symbols and folding regions computed (limited for performance reasons)."
}

View File

@@ -63,6 +63,7 @@ The server supports the following settings:
- `fileMatch`: an array of file names or paths (separated by `/`). `*` can be used as a wildcard.
- `url`: The URL of the schema, optional when also a schema is provided.
- `schema`: The schema content.
- `resultLimit`: The max number foldig ranges and otline symbols to be computed (for performance reasons)
```json
{
@@ -153,6 +154,16 @@ Notification:
- method: 'json/schemaContent'
- params: `string` the URL of the schema that has changed.
### Item Limit
If the setting `resultLimit` is set, the JSON language server will limit the number of folding ranges and document symbols computed.
When the limit is reached, a notification `json/resultLimitReached` is sent that can be shown that camn be shown to the user.
Notification:
- method: 'json/resultLimitReached'
- params: a human readable string to show to the user.
## Try
The JSON language server is shipped with [Visual Studio Code](https://code.visualstudio.com/) as part of the built-in VSCode extension `json-language-features`. The server is started when the first JSON file is opened. The [VSCode JSON documentation](https://code.visualstudio.com/docs/languages/json) for detailed information on the user experience and has more information on how to configure the language support.

View File

@@ -14,7 +14,7 @@
"dependencies": {
"jsonc-parser": "^2.2.0",
"request-light": "^0.2.5",
"vscode-json-languageservice": "^3.4.7",
"vscode-json-languageservice": "^3.4.9",
"vscode-languageserver": "^6.0.0-next.3",
"vscode-uri": "^2.1.1"
},

View File

@@ -35,6 +35,10 @@ namespace SchemaContentChangeNotification {
export const type: NotificationType<string, any> = new NotificationType('json/schemaContent');
}
namespace ResultLimitReachedNotification {
export const type: NotificationType<string, any> = new NotificationType('json/resultLimitReached');
}
namespace ForceValidateRequest {
export const type: RequestType<string, Diagnostic[], any, any> = new RequestType('json/validate');
}
@@ -211,7 +215,7 @@ namespace LimitExceededWarnings {
} else {
warning = { features: { [name]: name } };
warning.timeout = setTimeout(() => {
connection.window.showInformationMessage(`${posix.basename(uri)}: For performance reasons, ${Object.keys(warning.features).join(' and ')} have been limited to ${resultLimit} items.`);
connection.sendNotification(ResultLimitReachedNotification.type, `${posix.basename(uri)}: For performance reasons, ${Object.keys(warning.features).join(' and ')} have been limited to ${resultLimit} items.`);
warning.timeout = undefined;
}, 2000);
pendingWarnings[uri] = warning;

View File

@@ -80,10 +80,10 @@ request-light@^0.2.5:
https-proxy-agent "^2.2.3"
vscode-nls "^4.1.1"
vscode-json-languageservice@^3.4.7:
version "3.4.7"
resolved "https://registry.yarnpkg.com/vscode-json-languageservice/-/vscode-json-languageservice-3.4.7.tgz#8d85f3c1d46a1e58e9867d747552fb8c83d934fd"
integrity sha512-y3MN2+/yph3yoIHGmHu4ScYpm285L58XVvfGkd49xTQzLja4apxSbwzsYcP9QsqS0W7KuvoyiPhqksiudoMwjg==
vscode-json-languageservice@^3.4.9:
version "3.4.9"
resolved "https://registry.yarnpkg.com/vscode-json-languageservice/-/vscode-json-languageservice-3.4.9.tgz#7ce485bb0f9a07b4d879c988baac9be2222909ad"
integrity sha512-4VCpZ9ooea/Zc/MTnj1ccc9C7rqcoinKVQLhLoi6jw6yueSf4y4tg/YIUiPPVMlEAG7ZCPS+NVmqxisQ+mOsSw==
dependencies:
jsonc-parser "^2.2.0"
vscode-languageserver-textdocument "^1.0.0-next.4"

View File

@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Markdown contributions to package.json",
"type": "object",
"properties": {
@@ -29,4 +29,4 @@
}
}
}
}
}

View File

@@ -249,8 +249,11 @@ export class MarkdownEngine {
if (uri.path[0] === '/') {
const root = vscode.workspace.getWorkspaceFolder(this.currentDocument!);
if (root) {
uri = uri.with({
path: path.join(root.uri.fsPath, uri.path),
const fileUri = vscode.Uri.file(path.join(root.uri.fsPath, uri.fsPath));
uri = fileUri.with({
scheme: uri.scheme,
fragment: uri.fragment,
query: uri.query,
});
}
}

View File

@@ -3,7 +3,7 @@
"version": "0.0.1",
"description": "Dependencies shared by all extensions",
"dependencies": {
"typescript": "3.7.3-insiders.20191123"
"typescript": "3.7.3"
},
"scripts": {
"postinstall": "node ./postinstall"

View File

@@ -19,6 +19,11 @@
"vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.js compile-extension:search-result ./tsconfig.json"
},
"contributes": {
"configurationDefaults": {
"[search-result]": {
"editor.lineNumbers": "off"
}
},
"commands": [
{
"command": "searchResult.rerunSearch",
@@ -28,6 +33,15 @@
"light": "./src/media/refresh-light.svg",
"dark": "./src/media/refresh-dark.svg"
}
},
{
"command": "searchResult.rerunSearchWithContext",
"title": "%searchResult.rerunSearchWithContext.title%",
"category": "Search Result",
"icon": {
"light": "./src/media/refresh-light.svg",
"dark": "./src/media/refresh-dark.svg"
}
}
],
"menus": {
@@ -35,6 +49,7 @@
{
"command": "searchResult.rerunSearch",
"when": "editorLangId == search-result",
"alt": "searchResult.rerunSearchWithContext",
"group": "navigation"
}
]

View File

@@ -1,5 +1,6 @@
{
"displayName": "Search Result",
"description": "Provides syntax highlighting and language features for tabbed search results.",
"searchResult.rerunSearch.title": "Search Again"
"searchResult.rerunSearch.title": "Search Again",
"searchResult.rerunSearchWithContext.title": "Search Again (With Context)"
}

View File

@@ -7,81 +7,93 @@ import * as vscode from 'vscode';
import * as pathUtils from 'path';
const FILE_LINE_REGEX = /^(\S.*):$/;
const RESULT_LINE_REGEX = /^(\s+)(\d+):(\s+)(.*)$/;
const RESULT_LINE_REGEX = /^(\s+)(\d+)(:| )(\s+)(.*)$/;
const SEARCH_RESULT_SELECTOR = { language: 'search-result' };
const DIRECTIVES = ['# Query:', '# Flags:', '# Including:', '# Excluding:', '# ContextLines:'];
const FLAGS = ['RegExp', 'CaseSensitive', 'IgnoreExcludeSettings', 'WordMatch'];
let cachedLastParse: { version: number, parse: ParsedSearchResults } | undefined;
export function activate() {
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.commands.registerCommand('searchResult.rerunSearch', () => vscode.commands.executeCommand('search.action.rerunEditorSearch')),
vscode.commands.registerCommand('searchResult.rerunSearchWithContext', () => vscode.commands.executeCommand('search.action.rerunEditorSearchWithContext')),
vscode.commands.registerCommand('searchResult.rerunSearch', () => vscode.commands.executeCommand('search.action.rerunEditorSearch'));
vscode.languages.registerDocumentSymbolProvider(SEARCH_RESULT_SELECTOR, {
provideDocumentSymbols(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.DocumentSymbol[] {
const results = parseSearchResults(document, token)
.filter(isFileLine)
.map(line => new vscode.DocumentSymbol(
line.path,
'',
vscode.SymbolKind.File,
line.allLocations.map(({ originSelectionRange }) => originSelectionRange!).reduce((p, c) => p.union(c), line.location.originSelectionRange!),
line.location.originSelectionRange!,
));
vscode.languages.registerDocumentSymbolProvider(SEARCH_RESULT_SELECTOR, {
provideDocumentSymbols(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.DocumentSymbol[] {
const results = parseSearchResults(document, token)
.filter(isFileLine)
.map(line => new vscode.DocumentSymbol(
line.path,
'',
vscode.SymbolKind.File,
line.allLocations.map(({ originSelectionRange }) => originSelectionRange!).reduce((p, c) => p.union(c), line.location.originSelectionRange!),
line.location.originSelectionRange!,
));
return results;
}
});
vscode.languages.registerCompletionItemProvider(SEARCH_RESULT_SELECTOR, {
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem[] {
const line = document.lineAt(position.line);
if (position.line > 3) { return []; }
if (position.character === 0 || (position.character === 1 && line.text === '#')) {
const header = Array.from({ length: 4 }).map((_, i) => document.lineAt(i).text);
return ['# Query:', '# Flags:', '# Including:', '# Excluding:']
.filter(suggestion => header.every(line => line.indexOf(suggestion) === -1))
.map(flag => ({ label: flag, insertText: (flag.slice(position.character)) + ' ' }));
return results;
}
}),
if (line.text.indexOf('# Flags:') === -1) { return []; }
vscode.languages.registerCompletionItemProvider(SEARCH_RESULT_SELECTOR, {
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem[] {
return ['RegExp', 'CaseSensitive', 'IgnoreExcludeSettings', 'WordMatch']
.filter(flag => line.text.indexOf(flag) === -1)
.map(flag => ({ label: flag, insertText: flag + ' ' }));
}
}, '#');
const line = document.lineAt(position.line);
if (position.line > 3) { return []; }
if (position.character === 0 || (position.character === 1 && line.text === '#')) {
const header = Array.from({ length: DIRECTIVES.length }).map((_, i) => document.lineAt(i).text);
vscode.languages.registerDefinitionProvider(SEARCH_RESULT_SELECTOR, {
provideDefinition(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): vscode.DefinitionLink[] {
const lineResult = parseSearchResults(document, token)[position.line];
if (!lineResult) { return []; }
if (lineResult.type === 'file') {
// TODO: The multi-match peek UX isnt very smooth.
// return lineResult.allLocations.length > 1 ? lineResult.allLocations : [lineResult.location];
return [];
return DIRECTIVES
.filter(suggestion => header.every(line => line.indexOf(suggestion) === -1))
.map(flag => ({ label: flag, insertText: (flag.slice(position.character)) + ' ' }));
}
if (line.text.indexOf('# Flags:') === -1) { return []; }
return FLAGS
.filter(flag => line.text.indexOf(flag) === -1)
.map(flag => ({ label: flag, insertText: flag + ' ' }));
}
}, '#'),
return [lineResult.location];
}
});
vscode.languages.registerDefinitionProvider(SEARCH_RESULT_SELECTOR, {
provideDefinition(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): vscode.DefinitionLink[] {
const lineResult = parseSearchResults(document, token)[position.line];
if (!lineResult) { return []; }
if (lineResult.type === 'file') {
// TODO: The multi-match peek UX isnt very smooth.
// return lineResult.allLocations.length > 1 ? lineResult.allLocations : [lineResult.location];
return [];
}
vscode.languages.registerDocumentLinkProvider(SEARCH_RESULT_SELECTOR, {
async provideDocumentLinks(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.DocumentLink[]> {
return parseSearchResults(document, token)
.filter(({ type }) => type === 'file')
.map(({ location }) => ({ range: location.originSelectionRange!, target: location.targetUri }));
}
});
const translateRangeSidewaysBy = (r: vscode.Range, n: number) =>
r.with({ start: new vscode.Position(r.start.line, Math.max(0, n - r.start.character)), end: new vscode.Position(r.end.line, Math.max(0, n - r.end.character)) });
vscode.window.onDidChangeActiveTextEditor(e => {
if (e?.document.languageId === 'search-result') {
// Clear the parse whenever we open a new editor.
// Conservative because things like the URI might remain constant even if the contents change, and re-parsing even large files is relatively fast.
cachedLastParse = undefined;
}
});
return [{
...lineResult.location,
targetSelectionRange: translateRangeSidewaysBy(lineResult.location.targetSelectionRange!, position.character - 1)
}];
}
}),
vscode.languages.registerDocumentLinkProvider(SEARCH_RESULT_SELECTOR, {
async provideDocumentLinks(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.DocumentLink[]> {
return parseSearchResults(document, token)
.filter(({ type }) => type === 'file')
.map(({ location }) => ({ range: location.originSelectionRange!, target: location.targetUri }));
}
}),
vscode.window.onDidChangeActiveTextEditor(e => {
if (e?.document.languageId === 'search-result') {
// Clear the parse whenever we open a new editor.
// Conservative because things like the URI might remain constant even if the contents change, and re-parsing even large files is relatively fast.
cachedLastParse = undefined;
}
}),
{ dispose() { cachedLastParse = undefined; } }
);
}
@@ -160,13 +172,14 @@ function parseSearchResults(document: vscode.TextDocument, token: vscode.Cancell
const resultLine = RESULT_LINE_REGEX.exec(line);
if (resultLine) {
const [, indentation, _lineNumber, resultIndentation] = resultLine;
const [, indentation, _lineNumber, seperator, resultIndentation] = resultLine;
const lineNumber = +_lineNumber - 1;
const resultStart = (indentation + _lineNumber + ':' + resultIndentation).length;
const resultStart = (indentation + _lineNumber + seperator + resultIndentation).length;
const metadataOffset = (indentation + _lineNumber + seperator).length;
const location: vscode.LocationLink = {
targetRange: new vscode.Range(Math.max(lineNumber - 3, 0), 0, lineNumber + 3, line.length),
targetSelectionRange: new vscode.Range(lineNumber, 0, lineNumber, line.length),
targetSelectionRange: new vscode.Range(lineNumber, metadataOffset, lineNumber, metadataOffset),
targetUri: currentTarget,
originSelectionRange: new vscode.Range(i, resultStart, i, line.length),
};

View File

@@ -3,7 +3,7 @@
"scopeName": "text.searchResult",
"patterns": [
{
"match": "^# (Query|Flags|Including|Excluding): .*$",
"match": "^# (Query|Flags|Including|Excluding|ContextLines): .*$",
"name": "comment"
},
{

View File

@@ -8,31 +8,43 @@ import * as jsoncParser from 'jsonc-parser';
export function activate(context: vscode.ExtensionContext): any {
const tokenModifiers = ['static', 'abstract', 'deprecated'];
const tokenTypes = ['strings', 'types', 'structs', 'classes', 'functions', 'variables'];
const tokenTypes = ['type', 'struct', 'class', 'interface', 'enum', 'parameterType', 'function', 'variable'];
const tokenModifiers = ['static', 'abstract', 'deprecated', 'declaration', 'documentation', 'member', 'async'];
const legend = new vscode.SemanticTokensLegend(tokenTypes, tokenModifiers);
const semanticHighlightProvider: vscode.SemanticTokensProvider = {
provideSemanticTokens(document: vscode.TextDocument): vscode.ProviderResult<vscode.SemanticTokens> {
const builder = new vscode.SemanticTokensBuilder();
function addToken(value: string, startLine: number, startCharacter: number, length: number) {
const [type, ...modifiers] = value.split('.');
let tokenType = legend.tokenTypes.indexOf(type);
if (tokenType === -1) {
return;
}
let tokenModifiers = 0;
for (let i = 0; i < modifiers.length; i++) {
const index = legend.tokenModifiers.indexOf(modifiers[i]);
if (index !== -1) {
tokenModifiers = tokenModifiers | 1 << index;
}
}
builder.push(startLine, startCharacter, length, tokenType, tokenModifiers);
}
const visitor: jsoncParser.JSONVisitor = {
onObjectProperty: (property: string, _offset: number, length: number, startLine: number, startCharacter: number) => {
const [type, ...modifiers] = property.split('.');
let tokenType = legend.tokenTypes.indexOf(type);
if (tokenType === -1) {
tokenType = 0;
onObjectProperty: (property: string, _offset: number, _length: number, startLine: number, startCharacter: number) => {
addToken(property, startLine, startCharacter, property.length + 2);
},
onLiteralValue: (value: any, _offset: number, length: number, startLine: number, startCharacter: number) => {
if (typeof value === 'string') {
addToken(value, startLine, startCharacter, length);
}
let tokenModifiers = 0;
for (let i = 0; i < modifiers.length; i++) {
const index = legend.tokenModifiers.indexOf(modifiers[i]);
if (index !== -1) {
tokenModifiers = tokenModifiers | 1 << index;
}
}
builder.push(startLine, startCharacter, length, tokenType, tokenModifiers);
}
};
jsoncParser.visit(document.getText(), visitor);
@@ -42,6 +54,6 @@ export function activate(context: vscode.ExtensionContext): any {
};
context.subscriptions.push(vscode.languages.registerSemanticTokensProvider({ pattern: '**/color-test.json' }, semanticHighlightProvider, legend));
context.subscriptions.push(vscode.languages.registerSemanticTokensProvider({ pattern: '**/*semantic-test.json' }, semanticHighlightProvider, legend));
}

View File

@@ -2,7 +2,7 @@
# yarn lockfile v1
typescript@3.7.3-insiders.20191123:
version "3.7.3-insiders.20191123"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.3-insiders.20191123.tgz#f3bef33a2a3f6e02f11bcc0c20b6f0de526f17fd"
integrity sha512-b+tLx4D0a6SeuaCa7iehdgkRKHsS67FkioQWw+0REjVNOYZ+AqJ0NjlnomK1hEUvSzSNrH9Du+m+Yiv7JlVpSg==
typescript@3.7.3:
version "3.7.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.3.tgz#b36840668a16458a7025b9eabfad11b66ab85c69"
integrity sha512-Mcr/Qk7hXqFBXMN7p7Lusj1ktCBydylfQM/FZCk5glCNQJrCUKPkMHdo9R0MTFWsC/4kPFvDS0fDPvukfCkFsw==