mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-01 05:51:32 +01:00
Converted json extension to new vscode-nls npm module
This commit is contained in:
@@ -6,11 +6,13 @@
|
||||
|
||||
import {MarkedString, CompletionItemKind} from 'vscode-languageserver';
|
||||
import Strings = require('../utils/strings');
|
||||
import nls = require('../utils/nls');
|
||||
import {IJSONWorkerContribution, ISuggestionsCollector} from '../jsonContributions';
|
||||
import {IRequestService} from '../jsonSchemaService';
|
||||
import {JSONLocation} from '../jsonLocation';
|
||||
|
||||
import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
export class BowerJSONContribution implements IJSONWorkerContribution {
|
||||
|
||||
private requestService : IRequestService;
|
||||
@@ -41,7 +43,7 @@ export class BowerJSONContribution implements IJSONWorkerContribution {
|
||||
'main': '{{pathToMain}}',
|
||||
'dependencies': {}
|
||||
};
|
||||
result.add({ kind: CompletionItemKind.Class, label: nls.localize('json.bower.default', 'Default bower.json'), insertText: JSON.stringify(defaultValue, null, '\t'), documentation: '' });
|
||||
result.add({ kind: CompletionItemKind.Class, label: localize('json.bower.default', 'Default bower.json'), insertText: JSON.stringify(defaultValue, null, '\t'), documentation: '' });
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -77,11 +79,11 @@ export class BowerJSONContribution implements IJSONWorkerContribution {
|
||||
// ignore
|
||||
}
|
||||
} else {
|
||||
result.error(nls.localize('json.bower.error.repoaccess', 'Request to the bower repository failed: {0}', success.responseText));
|
||||
result.error(localize('json.bower.error.repoaccess', 'Request to the bower repository failed: {0}', success.responseText));
|
||||
return 0;
|
||||
}
|
||||
}, (error) => {
|
||||
result.error(nls.localize('json.bower.error.repoaccess', 'Request to the bower repository failed: {0}', error.responseText));
|
||||
result.error(localize('json.bower.error.repoaccess', 'Request to the bower repository failed: {0}', error.responseText));
|
||||
return 0;
|
||||
});
|
||||
} else {
|
||||
@@ -110,7 +112,7 @@ export class BowerJSONContribution implements IJSONWorkerContribution {
|
||||
if (this.isBowerFile(resource) && (location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']))) {
|
||||
let pack = location.getSegments()[location.getSegments().length - 1];
|
||||
let htmlContent : MarkedString[] = [];
|
||||
htmlContent.push(nls.localize('json.bower.package.hover', '{0}', pack));
|
||||
htmlContent.push(localize('json.bower.package.hover', '{0}', pack));
|
||||
|
||||
let queryUrl = 'https://bower.herokuapp.com/packages/' + encodeURIComponent(pack);
|
||||
|
||||
|
||||
@@ -6,23 +6,25 @@
|
||||
|
||||
import {MarkedString, CompletionItemKind, CompletionItem} from 'vscode-languageserver';
|
||||
import Strings = require('../utils/strings');
|
||||
import nls = require('../utils/nls');
|
||||
import {IJSONWorkerContribution, ISuggestionsCollector} from '../jsonContributions';
|
||||
import {JSONLocation} from '../jsonLocation';
|
||||
|
||||
import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
let globProperties:CompletionItem[] = [
|
||||
{ kind: CompletionItemKind.Value, label: nls.localize('fileLabel', "Files by Extension"), insertText: '"**/*.{{extension}}": true', documentation: nls.localize('fileDescription', "Match all files of a specific file extension.")},
|
||||
{ kind: CompletionItemKind.Value, label: nls.localize('filesLabel', "Files with Multiple Extensions"), insertText: '"**/*.{ext1,ext2,ext3}": true', documentation: nls.localize('filesDescription', "Match all files with any of the file extensions.")},
|
||||
{ kind: CompletionItemKind.Value, label: nls.localize('derivedLabel', "Files with Siblings by Name"), insertText: '"**/*.{{source-extension}}": { "when": "$(basename).{{target-extension}}" }', documentation: nls.localize('derivedDescription', "Match files that have siblings with the same name but a different extension.")},
|
||||
{ kind: CompletionItemKind.Value, label: nls.localize('topFolderLabel', "Folder by Name (Top Level)"), insertText: '"{{name}}": true', documentation: nls.localize('topFolderDescription', "Match a top level folder with a specific name.")},
|
||||
{ kind: CompletionItemKind.Value, label: nls.localize('topFoldersLabel', "Folders with Multiple Names (Top Level)"), insertText: '"{folder1,folder2,folder3}": true', documentation: nls.localize('topFoldersDescription', "Match multiple top level folders.")},
|
||||
{ kind: CompletionItemKind.Value, label: nls.localize('folderLabel', "Folder by Name (Any Location)"), insertText: '"**/{{name}}": true', documentation: nls.localize('folderDescription', "Match a folder with a specific name in any location.")},
|
||||
{ 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('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('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.")},
|
||||
];
|
||||
|
||||
let globValues:CompletionItem[] = [
|
||||
{ kind: CompletionItemKind.Value, label: nls.localize('trueLabel', "True"), insertText: 'true', documentation: nls.localize('trueDescription', "Enable the pattern.")},
|
||||
{ kind: CompletionItemKind.Value, label: nls.localize('falseLabel', "False"), insertText: 'false', documentation: nls.localize('falseDescription', "Disable the pattern.")},
|
||||
{ kind: CompletionItemKind.Value, label: nls.localize('derivedLabel', "Files with Siblings by Name"), insertText: '{ "when": "$(basename).{{extension}}" }', documentation: nls.localize('siblingsDescription', "Match files that have siblings with the same name but a different extension.")}
|
||||
{ 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.")}
|
||||
];
|
||||
|
||||
export class GlobPatternContribution implements IJSONWorkerContribution {
|
||||
|
||||
@@ -6,11 +6,13 @@
|
||||
|
||||
import {MarkedString, CompletionItemKind} from 'vscode-languageserver';
|
||||
import Strings = require('../utils/strings');
|
||||
import nls = require('../utils/nls');
|
||||
import {IJSONWorkerContribution, ISuggestionsCollector} from '../jsonContributions';
|
||||
import {IRequestService} from '../jsonSchemaService';
|
||||
import {JSONLocation} from '../jsonLocation';
|
||||
|
||||
import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
let LIMIT = 40;
|
||||
|
||||
export class PackageJSONContribution implements IJSONWorkerContribution {
|
||||
@@ -42,7 +44,7 @@ export class PackageJSONContribution implements IJSONWorkerContribution {
|
||||
'main': '{{pathToMain}}',
|
||||
'dependencies': {}
|
||||
};
|
||||
result.add({ kind: CompletionItemKind.Module, label: nls.localize('json.package.default', 'Default package.json'), insertText: JSON.stringify(defaultValue, null, '\t'), documentation: '' });
|
||||
result.add({ kind: CompletionItemKind.Module, label: localize('json.package.default', 'Default package.json'), insertText: JSON.stringify(defaultValue, null, '\t'), documentation: '' });
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -83,11 +85,11 @@ export class PackageJSONContribution implements IJSONWorkerContribution {
|
||||
// ignore
|
||||
}
|
||||
} else {
|
||||
result.error(nls.localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', success.responseText));
|
||||
result.error(localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', success.responseText));
|
||||
return 0;
|
||||
}
|
||||
}, (error) => {
|
||||
result.error(nls.localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', error.responseText));
|
||||
result.error(localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', error.responseText));
|
||||
return 0;
|
||||
});
|
||||
} else {
|
||||
@@ -119,11 +121,11 @@ export class PackageJSONContribution implements IJSONWorkerContribution {
|
||||
if (obj && obj.version) {
|
||||
let version = obj.version;
|
||||
let name = JSON.stringify(version);
|
||||
result.add({ kind: CompletionItemKind.Class, label: name, insertText: name, documentation: nls.localize('json.npm.latestversion', 'The currently latest version of the package') });
|
||||
result.add({ kind: CompletionItemKind.Class, label: name, insertText: name, documentation: localize('json.npm.latestversion', 'The currently latest version of the package') });
|
||||
name = JSON.stringify('^' + version);
|
||||
result.add({ kind: CompletionItemKind.Class, label: name, insertText: name, documentation: nls.localize('json.npm.majorversion', 'Matches the most recent major version (1.x.x)') });
|
||||
result.add({ kind: CompletionItemKind.Class, label: name, insertText: name, documentation: localize('json.npm.majorversion', 'Matches the most recent major version (1.x.x)') });
|
||||
name = JSON.stringify('~' + version);
|
||||
result.add({ kind: CompletionItemKind.Class, label: name, insertText: name, documentation: nls.localize('json.npm.minorversion', 'Matches the most recent minor version (1.2.x)') });
|
||||
result.add({ kind: CompletionItemKind.Class, label: name, insertText: name, documentation: localize('json.npm.minorversion', 'Matches the most recent minor version (1.2.x)') });
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
@@ -141,7 +143,7 @@ export class PackageJSONContribution implements IJSONWorkerContribution {
|
||||
let pack = location.getSegments()[location.getSegments().length - 1];
|
||||
|
||||
let htmlContent : MarkedString[] = [];
|
||||
htmlContent.push(nls.localize('json.npm.package.hover', '{0}', pack));
|
||||
htmlContent.push(localize('json.npm.package.hover', '{0}', pack));
|
||||
|
||||
let queryUrl = 'http://registry.npmjs.org/' + encodeURIComponent(pack) + '/latest';
|
||||
|
||||
@@ -155,7 +157,7 @@ export class PackageJSONContribution implements IJSONWorkerContribution {
|
||||
htmlContent.push(obj.description);
|
||||
}
|
||||
if (obj.version) {
|
||||
htmlContent.push(nls.localize('json.npm.version.hover', 'Latest version: {0}', obj.version));
|
||||
htmlContent.push(localize('json.npm.version.hover', 'Latest version: {0}', obj.version));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -6,12 +6,15 @@
|
||||
|
||||
import {MarkedString, CompletionItemKind, CompletionItem} from 'vscode-languageserver';
|
||||
import Strings = require('../utils/strings');
|
||||
import nls = require('../utils/nls');
|
||||
import {IXHRResponse, getErrorStatusDescription} from '../utils/httpRequest';
|
||||
import {IJSONWorkerContribution, ISuggestionsCollector} from '../jsonContributions';
|
||||
import {IRequestService} from '../jsonSchemaService';
|
||||
import {JSONLocation} from '../jsonLocation';
|
||||
|
||||
import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
|
||||
const FEED_INDEX_URL = 'https://api.nuget.org/v3/index.json';
|
||||
const LIMIT = 30;
|
||||
const RESOLVE_ID = 'ProjectJSONContribution-';
|
||||
@@ -31,7 +34,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
|
||||
private cachedProjects: { [id: string]: { version: string, description: string, time: number }} = {};
|
||||
private cacheSize: number = 0;
|
||||
private nugetIndexPromise: Thenable<NugetServices>;
|
||||
|
||||
|
||||
public constructor(requestService: IRequestService) {
|
||||
this.requestService = requestService;
|
||||
}
|
||||
@@ -39,7 +42,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
|
||||
private isProjectJSONFile(resource: string): boolean {
|
||||
return Strings.endsWith(resource, '/project.json');
|
||||
}
|
||||
|
||||
|
||||
private completeWithCache(id: string, item: CompletionItem) : boolean {
|
||||
let entry = this.cachedProjects[id];
|
||||
if (entry) {
|
||||
@@ -61,7 +64,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
|
||||
this.cacheSize++;
|
||||
if (this.cacheSize > 50) {
|
||||
let currentTime = new Date().getTime() ;
|
||||
for (var id in this.cachedProjects) {
|
||||
for (let id in this.cachedProjects) {
|
||||
let entry = this.cachedProjects[id];
|
||||
if (currentTime - entry.time > CACHE_EXPIRY) {
|
||||
delete this.cachedProjects[id];
|
||||
@@ -70,7 +73,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private getNugetIndex() : Thenable<NugetServices> {
|
||||
if (!this.nugetIndexPromise) {
|
||||
this.nugetIndexPromise = this.makeJSONRequest<any>(FEED_INDEX_URL).then(indexContent => {
|
||||
@@ -95,7 +98,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
|
||||
return this.getNugetIndex().then(services => {
|
||||
let serviceURL = services[serviceType];
|
||||
if (!serviceURL) {
|
||||
return Promise.reject<string>(nls.localize('json.nugget.error.missingservice', 'NuGet index document is missing service {0}', serviceType));
|
||||
return Promise.reject<string>(localize('json.nugget.error.missingservice', 'NuGet index document is missing service {0}', serviceType));
|
||||
}
|
||||
return serviceURL;
|
||||
});
|
||||
@@ -111,7 +114,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
|
||||
'dnxcore50': {}
|
||||
}
|
||||
};
|
||||
result.add({ kind: CompletionItemKind.Class, label: nls.localize('json.project.default', 'Default project.json'), insertText: JSON.stringify(defaultValue, null, '\t'), documentation: '' });
|
||||
result.add({ kind: CompletionItemKind.Class, label: localize('json.project.default', 'Default project.json'), insertText: JSON.stringify(defaultValue, null, '\t'), documentation: '' });
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -124,12 +127,12 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
|
||||
try {
|
||||
return <T> JSON.parse(success.responseText);
|
||||
} catch (e) {
|
||||
return Promise.reject<T>(nls.localize('json.nugget.error.invalidformat', '{0} is not a valid JSON document', url));
|
||||
return Promise.reject<T>(localize('json.nugget.error.invalidformat', '{0} is not a valid JSON document', url));
|
||||
}
|
||||
}
|
||||
return Promise.reject<T>(nls.localize('json.nugget.error.indexaccess', 'Request to {0} failed: {1}', url, success.responseText));
|
||||
return Promise.reject<T>(localize('json.nugget.error.indexaccess', 'Request to {0} failed: {1}', url, success.responseText));
|
||||
}, (error: IXHRResponse) => {
|
||||
return Promise.reject<T>(nls.localize('json.nugget.error.access', 'Request to {0} failed: {1}', url, getErrorStatusDescription(error.status)));
|
||||
return Promise.reject<T>(localize('json.nugget.error.access', 'Request to {0} failed: {1}', url, getErrorStatusDescription(error.status)));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -211,7 +214,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
|
||||
let queryUrl = service + '?q=' + encodeURIComponent(pack) +'&take=' + 5;
|
||||
return this.makeJSONRequest<any>(queryUrl).then(resultObj => {
|
||||
let htmlContent : MarkedString[] = [];
|
||||
htmlContent.push(nls.localize('json.nugget.package.hover', '{0}', pack));
|
||||
htmlContent.push(localize('json.nugget.package.hover', '{0}', pack));
|
||||
if (Array.isArray(resultObj.data)) {
|
||||
let results = <any[]> resultObj.data;
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
@@ -222,7 +225,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
|
||||
htmlContent.push(res.description);
|
||||
}
|
||||
if (res.version) {
|
||||
htmlContent.push(nls.localize('json.nugget.version.hover', 'Latest version: {0}', res.version));
|
||||
htmlContent.push(localize('json.nugget.version.hover', 'Latest version: {0}', res.version));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -238,7 +241,7 @@ export class ProjectJSONContribution implements IJSONWorkerContribution {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public resolveSuggestion(item: CompletionItem) : Thenable<CompletionItem> {
|
||||
if (item.data && Strings.startsWith(item.data, RESOLVE_ID)) {
|
||||
let pack = item.data.substring(RESOLVE_ID.length);
|
||||
|
||||
Reference in New Issue
Block a user