mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 12:19:20 +00:00
[css/html/json] provide replace & insert proposals
This commit is contained in:
@@ -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';
|
||||
@@ -132,6 +140,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);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -422,5 +453,4 @@ function readJSONFile(location: string) {
|
||||
console.log(`Problems reading ${location}: ${e}`);
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,113 +1,114 @@
|
||||
{
|
||||
"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%"
|
||||
}
|
||||
}
|
||||
},
|
||||
"configurationDefaults": {
|
||||
"[json]": {
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user