提交 93c13342 编写于 作者: M Martin Aeschlimann

[json] adopt SnippetString (#15573) and update to TS 2.0

上级 63dbeee8
......@@ -14,7 +14,7 @@ import * as nls from 'vscode-nls';
let localize = nls.loadMessageBundle();
namespace VSCodeContentRequest {
export const type: RequestType<string, string, any> = { get method() { return 'vscode/content'; } };
export const type: RequestType<string, string, any, any> = { get method() { return 'vscode/content'; }, _: null };
}
export interface ISchemaAssociations {
......@@ -22,7 +22,7 @@ export interface ISchemaAssociations {
}
namespace SchemaAssociationNotification {
export const type: NotificationType<ISchemaAssociations> = { get method() { return 'json/schemaAssociations'; } };
export const type: NotificationType<ISchemaAssociations, any> = { get method() { return 'json/schemaAssociations'; }, _: null };
}
interface IPackageInfo {
......
......@@ -3,9 +3,4 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/// <reference path='../../../../../src/vs/vscode.d.ts'/>
/// <reference path='../../../../../src/typings/mocha.d.ts'/>
/// <reference path='../../../../../extensions/node.d.ts'/>
/// <reference path='../../../../../extensions/lib.core.d.ts'/>
/// <reference path='../../../../../extensions/declares.d.ts'/>
/// <reference path='../../../node_modules/vscode-languageclient/lib/main.d.ts'/>
\ No newline at end of file
/// <reference path='../../../../../src/vs/vscode.d.ts'/>
\ No newline at end of file
{
"compilerOptions": {
"noLib": true,
"target": "es5",
"module": "commonjs",
"outDir": "./out"
},
"exclude": [
"node_modules"
]
"outDir": "./out",
"lib": [
"es5", "es2015.promise"
]
}
}
\ No newline at end of file
......@@ -13,19 +13,19 @@
"resolved": "https://registry.npmjs.org/vscode-extension-telemetry/-/vscode-extension-telemetry-0.0.5.tgz"
},
"vscode-jsonrpc": {
"version": "2.3.2-next.5",
"from": "vscode-jsonrpc@>=2.3.2-next.2 <3.0.0",
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-2.3.2-next.5.tgz"
"version": "3.0.1-alpha.2",
"from": "vscode-jsonrpc@>=3.0.1-alpha.2 <4.0.0",
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-3.0.1-alpha.2.tgz"
},
"vscode-languageclient": {
"version": "2.4.2-next.22",
"version": "3.0.1-alpha.3",
"from": "vscode-languageclient@next",
"resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-2.4.2-next.22.tgz"
"resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-3.0.1-alpha.3.tgz"
},
"vscode-languageserver-types": {
"version": "1.0.3",
"from": "vscode-languageserver-types@>=1.0.3 <2.0.0",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-1.0.3.tgz"
"version": "3.0.1-alpha.2",
"from": "vscode-languageserver-types@>=3.0.1-alpha.2 <4.0.0",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.0.1-alpha.2.tgz"
},
"vscode-nls": {
"version": "1.0.7",
......
......@@ -66,9 +66,9 @@
"type": "object",
"default": {
"fileMatch": [
"{{/myfile}}"
"/myfile"
],
"url": "{{schemaURL}}"
"url": "schemaURL"
},
"properties": {
"url": {
......@@ -103,7 +103,10 @@
},
"dependencies": {
"vscode-extension-telemetry": "^0.0.5",
"vscode-languageclient": "^2.4.2-next.22",
"vscode-languageclient": "^3.0.1-alpha.3",
"vscode-nls": "^1.0.7"
},
"devDependencies": {
"@types/node": "^6.0.51"
}
}
\ No newline at end of file
}
......@@ -43,31 +43,24 @@
"resolved": "https://registry.npmjs.org/request-light/-/request-light-0.1.0.tgz"
},
"vscode-json-languageservice": {
"version": "2.0.0-next.2",
"version": "2.0.0-next.4",
"from": "vscode-json-languageservice@next",
"resolved": "https://registry.npmjs.org/vscode-json-languageservice/-/vscode-json-languageservice-2.0.0-next.2.tgz",
"dependencies": {
"vscode-languageserver-types": {
"version": "1.0.4",
"from": "vscode-languageserver-types@>=1.0.4 <2.0.0",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-1.0.4.tgz"
}
}
"resolved": "https://registry.npmjs.org/vscode-json-languageservice/-/vscode-json-languageservice-2.0.0-next.4.tgz"
},
"vscode-jsonrpc": {
"version": "2.3.2-next.5",
"from": "vscode-jsonrpc@>=2.3.2-next.2 <3.0.0",
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-2.3.2-next.5.tgz"
"version": "3.0.1-alpha.2",
"from": "vscode-jsonrpc@>=3.0.1-alpha.2 <4.0.0",
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-3.0.1-alpha.2.tgz"
},
"vscode-languageserver": {
"version": "2.4.0-next.12",
"version": "3.0.1-alpha.3",
"from": "vscode-languageserver@next",
"resolved": "https://registry.npmjs.org/vscode-languageserver/-/vscode-languageserver-2.4.0-next.12.tgz"
"resolved": "https://registry.npmjs.org/vscode-languageserver/-/vscode-languageserver-3.0.1-alpha.3.tgz"
},
"vscode-languageserver-types": {
"version": "1.0.3",
"from": "vscode-languageserver-types@>=1.0.3 <2.0.0",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-1.0.3.tgz"
"version": "3.0.1-alpha.2",
"from": "vscode-languageserver-types@>=3.0.1-alpha.2 <4.0.0",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.0.1-alpha.2.tgz"
},
"vscode-nls": {
"version": "1.0.7",
......
......@@ -9,9 +9,12 @@
},
"dependencies": {
"request-light": "^0.1.0",
"vscode-json-languageservice": "^2.0.0-next.2",
"vscode-languageserver": "^2.4.0-next.12",
"vscode-nls": "^1.0.4"
"vscode-json-languageservice": "^2.0.0-next.4",
"vscode-languageserver": "^3.0.1-alpha.3",
"vscode-nls": "^1.0.7"
},
"devDependencies": {
"@types/node": "^6.0.51"
},
"scripts": {
"compile": "gulp compile-extension:json-server",
......
......@@ -29,11 +29,11 @@ interface ISchemaAssociations {
}
namespace SchemaAssociationNotification {
export const type: NotificationType<ISchemaAssociations> = { get method() { return 'json/schemaAssociations'; } };
export const type: NotificationType<ISchemaAssociations, any> = { get method() { return 'json/schemaAssociations'; }, _: null };
}
namespace VSCodeContentRequest {
export const type: RequestType<string, string, any> = { get method() { return 'vscode/content'; } };
export const type: RequestType<string, string, any, any> = { get method() { return 'vscode/content'; }, _: null };
}
// Create a connection for the server
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { MarkedString, CompletionItemKind, CompletionItem } from 'vscode-languageserver';
import { MarkedString, CompletionItemKind, CompletionItem, SnippetString } from 'vscode-languageserver';
import Strings = require('../utils/strings');
import { JSONWorkerContribution, JSONPath, CompletionsCollector } from 'vscode-json-languageservice';
......@@ -12,8 +12,8 @@ import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
let globProperties: CompletionItem[] = [
{ kind: CompletionItemKind.Value, label: localize('assocLabelFile', "Files with Extension"), insertText: '"*.{{extension}}": "{{language}}"', documentation: localize('assocDescriptionFile', "Map all files matching the glob pattern in their filename to the language with the given identifier.") },
{ kind: CompletionItemKind.Value, label: localize('assocLabelPath', "Files with Path"), insertText: '"/{{path to file}}/*.{{extension}}": "{{language}}"', documentation: localize('assocDescriptionPath', "Map all files matching the absolute path glob pattern in their path to the language with the given identifier.") }
{ kind: CompletionItemKind.Value, label: localize('assocLabelFile', "Files with Extension"), insertText: SnippetString.create('"*.${1:extension}": "${2:language}"'), documentation: localize('assocDescriptionFile', "Map all files matching the glob pattern in their filename to the language with the given identifier.") },
{ kind: CompletionItemKind.Value, label: localize('assocLabelPath', "Files with Path"), insertText: SnippetString.create('"/${1:path to file}/*.${2:extension}": "${3:language}"'), documentation: localize('assocDescriptionPath', "Map all files matching the absolute path glob pattern in their path to the language with the given identifier.") }
];
export class FileAssociationContribution implements JSONWorkerContribution {
......@@ -37,7 +37,6 @@ export class FileAssociationContribution implements JSONWorkerContribution {
public collectPropertyCompletions(resource: string, location: JSONPath, currentWord: string, addValue: boolean, isLast: boolean, result: CompletionsCollector): Thenable<any> {
if (this.isSettingsFile(resource) && location.length === 1 && location[0] === 'files.associations') {
globProperties.forEach(e => {
e.filterText = e.insertText;
result.add(e);
});
}
......@@ -51,7 +50,7 @@ export class FileAssociationContribution implements JSONWorkerContribution {
result.add({
kind: CompletionItemKind.Value,
label: l,
insertText: JSON.stringify('{{' + l + '}}'),
insertText: SnippetString.create(JSON.stringify('${1:' + l + '}')),
filterText: JSON.stringify(l)
});
});
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { MarkedString, CompletionItemKind, CompletionItem } from 'vscode-languageserver';
import { MarkedString, CompletionItemKind, CompletionItem, SnippetString } from 'vscode-languageserver';
import Strings = require('../utils/strings');
import { JSONWorkerContribution, JSONPath, CompletionsCollector } from 'vscode-json-languageservice';
......@@ -12,18 +12,18 @@ import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
let globProperties: CompletionItem[] = [
{ kind: CompletionItemKind.Value, label: localize('fileLabel', "Files by Extension"), insertText: '"**/*.{{extension}}": true', documentation: localize('fileDescription', "Match all files of a specific file extension.") },
{ kind: CompletionItemKind.Value, label: localize('fileLabel', "Files by Extension"), insertText: SnippetString.create('"**/*.${1:extension}": true'), documentation: localize('fileDescription', "Match all files of a specific file extension.") },
{ kind: CompletionItemKind.Value, label: localize('filesLabel', "Files with Multiple Extensions"), insertText: '"**/*.{ext1,ext2,ext3}": true', documentation: localize('filesDescription', "Match all files with any of the file extensions.") },
{ kind: CompletionItemKind.Value, label: localize('derivedLabel', "Files with Siblings by Name"), insertText: '"**/*.{{source-extension}}": { "when": "$(basename).{{target-extension}}" }', documentation: localize('derivedDescription', "Match files that have siblings with the same name but a different extension.") },
{ kind: CompletionItemKind.Value, label: localize('topFolderLabel', "Folder by Name (Top Level)"), insertText: '"{{name}}": true', documentation: localize('topFolderDescription', "Match a top level folder with a specific name.") },
{ kind: CompletionItemKind.Value, label: localize('derivedLabel', "Files with Siblings by Name"), insertText: SnippetString.create('"**/*.${1:source-extension}": { "when": "$(basename).{{target-extension}}" }'), documentation: localize('derivedDescription', "Match files that have siblings with the same name but a different extension.") },
{ kind: CompletionItemKind.Value, label: localize('topFolderLabel', "Folder by Name (Top Level)"), insertText: SnippetString.create('"${1:name}": true'), documentation: localize('topFolderDescription', "Match a top level folder with a specific name.") },
{ kind: CompletionItemKind.Value, label: localize('topFoldersLabel', "Folders with Multiple Names (Top Level)"), insertText: '"{folder1,folder2,folder3}": true', documentation: localize('topFoldersDescription', "Match multiple top level folders.") },
{ kind: CompletionItemKind.Value, label: localize('folderLabel', "Folder by Name (Any Location)"), insertText: '"**/{{name}}": true', documentation: localize('folderDescription', "Match a folder with a specific name in any location.") },
{ kind: CompletionItemKind.Value, label: localize('folderLabel', "Folder by Name (Any Location)"), insertText: SnippetString.create('"**/${1:name}": true'), documentation: localize('folderDescription', "Match a folder with a specific name in any location.") },
];
let globValues: CompletionItem[] = [
{ kind: CompletionItemKind.Value, label: localize('trueLabel', "true"), insertText: 'true', documentation: localize('trueDescription', "Enable the pattern.") },
{ kind: CompletionItemKind.Value, label: localize('falseLabel', "false"), insertText: 'false', documentation: localize('falseDescription', "Disable the pattern.") },
{ kind: CompletionItemKind.Value, label: localize('derivedLabel', "Files with Siblings by Name"), insertText: '{ "when": "$(basename).{{extension}}" }', documentation: localize('siblingsDescription', "Match files that have siblings with the same name but a different extension.") }
{ kind: CompletionItemKind.Value, label: localize('trueLabel', "true"), filterText: 'true', insertText: 'true', documentation: localize('trueDescription', "Enable the pattern.") },
{ kind: CompletionItemKind.Value, label: localize('falseLabel', "false"), filterText: 'false', insertText: 'false', documentation: localize('falseDescription', "Disable the pattern.") },
{ kind: CompletionItemKind.Value, label: localize('derivedLabel', "Files with Siblings by Name"), insertText: SnippetString.create('{ "when": "$(basename).${1:extension}" }'), documentation: localize('siblingsDescription', "Match files that have siblings with the same name but a different extension.") }
];
export class GlobPatternContribution implements JSONWorkerContribution {
......@@ -42,7 +42,6 @@ export class GlobPatternContribution implements JSONWorkerContribution {
public collectPropertyCompletions(resource: string, location: JSONPath, currentWord: string, addValue: boolean, isLast: boolean, result: CompletionsCollector): Thenable<any> {
if (this.isSettingsFile(resource) && location.length === 1 && ((location[0] === 'files.exclude') || (location[0] === 'search.exclude'))) {
globProperties.forEach(e => {
e.filterText = e.insertText;
result.add(e);
});
}
......@@ -53,7 +52,6 @@ export class GlobPatternContribution implements JSONWorkerContribution {
public collectValueCompletions(resource: string, location: JSONPath, currentKey: string, result: CompletionsCollector): Thenable<any> {
if (this.isSettingsFile(resource) && location.length === 1 && ((location[0] === 'files.exclude') || (location[0] === 'search.exclude'))) {
globValues.forEach(e => {
e.filterText = e.insertText;
result.add(e);
});
}
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { MarkedString, CompletionItemKind, CompletionItem } from 'vscode-languageserver';
import { MarkedString, CompletionItemKind, CompletionItem, SnippetString } from 'vscode-languageserver';
import Strings = require('../utils/strings');
import { XHRResponse, getErrorStatusDescription, xhr } from 'request-light';
import { JSONWorkerContribution, JSONPath, CompletionsCollector } from 'vscode-json-languageservice';
......@@ -47,9 +47,10 @@ export class ProjectJSONContribution implements JSONWorkerContribution {
this.cacheSize--;
return false;
}
let insertTextValue = (<SnippetString>item.insertText).value;
item.detail = entry.version;
item.documentation = entry.description;
item.insertText = item.insertText.replace(/\{\{\}\}/, '{{' + entry.version + '}}');
item.insertText = insertTextValue.replace(/\$1/, '${1:' + entry.version + '}');
return true;
}
return false;
......@@ -102,15 +103,15 @@ export class ProjectJSONContribution implements JSONWorkerContribution {
public collectDefaultCompletions(resource: string, result: CompletionsCollector): Thenable<any> {
if (this.isProjectJSONFile(resource)) {
let defaultValue = {
'version': '{{1.0.0-*}}',
let insertText = SnippetString.create(JSON.stringify({
'version': '${1:1.0.0-*}',
'dependencies': {},
'frameworks': {
'net461': {},
'netcoreapp1.0': {}
}
};
result.add({ kind: CompletionItemKind.Class, label: localize('json.project.default', 'Default project.json'), insertText: JSON.stringify(defaultValue, null, '\t'), documentation: '' });
}, null, '\t'));
result.add({ kind: CompletionItemKind.Class, label: localize('json.project.default', 'Default project.json'), insertText, documentation: '' });
}
return null;
}
......@@ -149,12 +150,12 @@ export class ProjectJSONContribution implements JSONWorkerContribution {
let name = results[i];
let insertText = JSON.stringify(name);
if (addValue) {
insertText += ': "{{}}"';
insertText += ': "$1"';
if (!isLast) {
insertText += ',';
}
}
let item: CompletionItem = { kind: CompletionItemKind.Property, label: name, insertText: insertText, filterText: JSON.stringify(name) };
let item: CompletionItem = { kind: CompletionItemKind.Property, label: name, insertText: SnippetString.create(insertText), filterText: JSON.stringify(name) };
if (!this.completeWithCache(name, item)) {
item.data = RESOLVE_ID + name;
}
......
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/**
* The Thenable (E.g. PromiseLike) and Promise declarions are taken from TypeScript's
* lib.core.es6.d.ts file. See above Copyright notice.
*/
/**
* Thenable is a common denominator between ES6 promises, Q, jquery.Deferred, WinJS.Promise,
* and others. This API makes no assumption about what promise libary is being used which
* enables reusing existing code without migrating to a specific promise implementation. Still,
* we recommand the use of native promises which are available in VS Code.
*/
interface Thenable<T> {
/**
* Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of which ever callback is executed.
*/
then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => TResult | Thenable<TResult>): Thenable<TResult>;
then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => void): Thenable<TResult>;
}
/**
* Represents the completion of an asynchronous operation
*/
interface Promise<T> extends Thenable<T> {
/**
* Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of which ever callback is executed.
*/
then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => TResult | Thenable<TResult>): Promise<TResult>;
then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => void): Promise<TResult>;
/**
* Attaches a callback for only the rejection of the Promise.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of the callback.
*/
catch(onrejected?: (reason: any) => T | Thenable<T>): Promise<T>;
}
interface PromiseConstructor {
/**
* Creates a new Promise.
* @param executor A callback used to initialize the promise. This callback is passed two arguments:
* a resolve callback used resolve the promise with a value or the result of another promise,
* and a reject callback used to reject the promise with a provided reason or error.
*/
new <T>(executor: (resolve: (value?: T | Thenable<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T>(values: Array<T | Thenable<T>>): Promise<T[]>;
/**
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
race<T>(values: Array<T | Thenable<T>>): Promise<T>;
/**
* Creates a new rejected promise for the provided reason.
* @param reason The reason the promise was rejected.
* @returns A new rejected Promise.
*/
reject(reason: any): Promise<void>;
/**
* Creates a new rejected promise for the provided reason.
* @param reason The reason the promise was rejected.
* @returns A new rejected Promise.
*/
reject<T>(reason: any): Promise<T>;
/**
* Creates a new resolved promise for the provided value.
* @param value A promise.
* @returns A promise whose internal state matches the provided promise.
*/
resolve<T>(value: T | Thenable<T>): Promise<T>;
/**
* Creates a new resolved promise .
* @returns A resolved promise.
*/
resolve(): Promise<void>;
}
declare var Promise: PromiseConstructor;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/// <reference path='../../../../../src/typings/mocha.d.ts'/>
/// <reference path='../../../../../extensions/node.d.ts'/>
/// <reference path='../../../../../extensions/lib.core.d.ts'/>
/// <reference path='../../../../../extensions/declares.d.ts'/>
\ No newline at end of file
{
"compilerOptions": {
"noLib": true,
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"sourceRoot": "../src",
"outDir": "./out"
"outDir": "./out",
"lib": [
"es5", "es2015.promise"
]
},
"exclude": [
"node_modules"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册