mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-01 05:51:32 +01:00
JSON completion contributors
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
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';
|
||||
|
||||
export class BowerJSONContribution implements IJSONWorkerContribution {
|
||||
|
||||
private requestService : IRequestService;
|
||||
|
||||
private topRanked = ['twitter','bootstrap','angular-1.1.6','angular-latest','angulerjs','d3','myjquery','jq','abcdef1234567890','jQuery','jquery-1.11.1','jquery',
|
||||
'sushi-vanilla-x-data','font-awsome','Font-Awesome','font-awesome','fontawesome','html5-boilerplate','impress.js','homebrew',
|
||||
'backbone','moment1','momentjs','moment','linux','animate.css','animate-css','reveal.js','jquery-file-upload','blueimp-file-upload','threejs','express','chosen',
|
||||
'normalize-css','normalize.css','semantic','semantic-ui','Semantic-UI','modernizr','underscore','underscore1',
|
||||
'material-design-icons','ionic','chartjs','Chart.js','nnnick-chartjs','select2-ng','select2-dist','phantom','skrollr','scrollr','less.js','leancss','parser-lib',
|
||||
'hui','bootstrap-languages','async','gulp','jquery-pjax','coffeescript','hammer.js','ace','leaflet','jquery-mobile','sweetalert','typeahead.js','soup','typehead.js',
|
||||
'sails','codeigniter2'];
|
||||
|
||||
public constructor(requestService: IRequestService) {
|
||||
this.requestService = requestService;
|
||||
}
|
||||
|
||||
private isBowerFile(resource: string): boolean {
|
||||
return Strings.endsWith(resource, '/bower.json') || Strings.endsWith(resource, '/.bower.json');
|
||||
}
|
||||
|
||||
public collectDefaultSuggestions(resource: string, result: ISuggestionsCollector): Thenable<any> {
|
||||
if (this.isBowerFile(resource)) {
|
||||
let defaultValue = {
|
||||
'name': '{{name}}',
|
||||
'description': '{{description}}',
|
||||
'authors': [ '{{author}}' ],
|
||||
'version': '{{1.0.0}}',
|
||||
'main': '{{pathToMain}}',
|
||||
'dependencies': {}
|
||||
};
|
||||
result.add({ kind: CompletionItemKind.Class, label: nls.localize('json.bower.default', 'Default bower.json'), insertText: JSON.stringify(defaultValue, null, '\t'), documentation: '' });
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public collectPropertySuggestions(resource: string, location: JSONLocation, currentWord: string, addValue: boolean, isLast:boolean, result: ISuggestionsCollector) : Thenable<any> {
|
||||
if (this.isBowerFile(resource) && (location.matches(['dependencies']) || location.matches(['devDependencies']))) {
|
||||
if (currentWord.length > 0) {
|
||||
let queryUrl = 'https://bower.herokuapp.com/packages/search/' + encodeURIComponent(currentWord);
|
||||
|
||||
return this.requestService({
|
||||
url : queryUrl
|
||||
}).then((success) => {
|
||||
if (success.status === 200) {
|
||||
try {
|
||||
let obj = JSON.parse(success.responseText);
|
||||
if (Array.isArray(obj)) {
|
||||
let results = <{name:string; description:string;}[]> obj;
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
let name = results[i].name;
|
||||
let description = results[i].description || '';
|
||||
let insertText = JSON.stringify(name);
|
||||
if (addValue) {
|
||||
insertText += ': "{{*}}"';
|
||||
if (!isLast) {
|
||||
insertText += ',';
|
||||
}
|
||||
}
|
||||
result.add({ kind: CompletionItemKind.Property, label: name, insertText: insertText, documentation: description });
|
||||
}
|
||||
result.setAsIncomplete();
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
} else {
|
||||
result.error(nls.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));
|
||||
return 0;
|
||||
});
|
||||
} else {
|
||||
this.topRanked.forEach((name) => {
|
||||
let insertText = JSON.stringify(name);
|
||||
if (addValue) {
|
||||
insertText += ': "{{*}}"';
|
||||
if (!isLast) {
|
||||
insertText += ',';
|
||||
}
|
||||
}
|
||||
result.add({ kind: CompletionItemKind.Property, label: name, insertText: insertText, documentation: '' });
|
||||
});
|
||||
result.setAsIncomplete();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public collectValueSuggestions(resource: string, location: JSONLocation, currentKey: string, result: ISuggestionsCollector): Thenable<any> {
|
||||
// not implemented. Could be do done calling the bower command. Waiting for web API: https://github.com/bower/registry/issues/26
|
||||
return null;
|
||||
}
|
||||
|
||||
public getInfoContribution(resource: string, location: JSONLocation): Thenable<MarkedString[]> {
|
||||
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));
|
||||
|
||||
let queryUrl = 'https://bower.herokuapp.com/packages/' + encodeURIComponent(pack);
|
||||
|
||||
return this.requestService({
|
||||
url : queryUrl
|
||||
}).then((success) => {
|
||||
try {
|
||||
let obj = JSON.parse(success.responseText);
|
||||
if (obj && obj.url) {
|
||||
let url = obj.url;
|
||||
if (Strings.startsWith(url, 'git://')) {
|
||||
url = url.substring(6);
|
||||
}
|
||||
if (Strings.endsWith(url, '.git')) {
|
||||
url = url.substring(0, url.length - 4);
|
||||
}
|
||||
htmlContent.push(url);
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
return htmlContent;
|
||||
}, (error) => {
|
||||
return htmlContent;
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import {MarkedString, CompletionItemKind, CompletionItem} 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';
|
||||
|
||||
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.")},
|
||||
];
|
||||
|
||||
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.")}
|
||||
];
|
||||
|
||||
export class GlobPatternContribution implements IJSONWorkerContribution {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
private isSettingsFile(resource: string): boolean {
|
||||
return Strings.endsWith(resource, '/settings.json');
|
||||
}
|
||||
|
||||
public collectDefaultSuggestions(resource: string, result: ISuggestionsCollector): Thenable<any> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public collectPropertySuggestions(resource: string, location: JSONLocation, currentWord: string, addValue: boolean, isLast:boolean, result: ISuggestionsCollector) : Thenable<any> {
|
||||
if (this.isSettingsFile(resource) && (location.matches(['files.exclude']) || location.matches(['search.exclude']))) {
|
||||
|
||||
globProperties.forEach((e) => result.add(e));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public collectValueSuggestions(resource: string, location: JSONLocation, currentKey: string, result: ISuggestionsCollector): Thenable<any> {
|
||||
if (this.isSettingsFile(resource) && (location.matches(['files.exclude']) || location.matches(['search.exclude']))) {
|
||||
|
||||
globValues.forEach((e) => result.add(e));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public getInfoContribution(resource: string, location: JSONLocation): Thenable<MarkedString[]> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import {MarkedString, CompletionItemKind, CompletionItem} 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';
|
||||
|
||||
let LIMIT = 40;
|
||||
|
||||
export class PackageJSONContribution implements IJSONWorkerContribution {
|
||||
|
||||
private mostDependedOn = [ 'lodash', 'async', 'underscore', 'request', 'commander', 'express', 'debug', 'chalk', 'colors', 'q', 'coffee-script',
|
||||
'mkdirp', 'optimist', 'through2', 'yeoman-generator', 'moment', 'bluebird', 'glob', 'gulp-util', 'minimist', 'cheerio', 'jade', 'redis', 'node-uuid',
|
||||
'socket', 'io', 'uglify-js', 'winston', 'through', 'fs-extra', 'handlebars', 'body-parser', 'rimraf', 'mime', 'semver', 'mongodb', 'jquery',
|
||||
'grunt', 'connect', 'yosay', 'underscore', 'string', 'xml2js', 'ejs', 'mongoose', 'marked', 'extend', 'mocha', 'superagent', 'js-yaml', 'xtend',
|
||||
'shelljs', 'gulp', 'yargs', 'browserify', 'minimatch', 'react', 'less', 'prompt', 'inquirer', 'ws', 'event-stream', 'inherits', 'mysql', 'esprima',
|
||||
'jsdom', 'stylus', 'when', 'readable-stream', 'aws-sdk', 'concat-stream', 'chai', 'Thenable', 'wrench'];
|
||||
|
||||
private requestService : IRequestService;
|
||||
|
||||
private isPackageJSONFile(resource: string): boolean {
|
||||
return Strings.endsWith(resource, '/package.json');
|
||||
}
|
||||
|
||||
public constructor(requestService: IRequestService) {
|
||||
this.requestService = requestService;
|
||||
}
|
||||
|
||||
public collectDefaultSuggestions(resource: string, result: ISuggestionsCollector): Thenable<any> {
|
||||
if (this.isPackageJSONFile(resource)) {
|
||||
let defaultValue = {
|
||||
'name': '{{name}}',
|
||||
'description': '{{description}}',
|
||||
'author': '{{author}}',
|
||||
'version': '{{1.0.0}}',
|
||||
'main': '{{pathToMain}}',
|
||||
'dependencies': {}
|
||||
};
|
||||
result.add({ kind: CompletionItemKind.Module, label: nls.localize('json.package.default', 'Default package.json'), insertText: JSON.stringify(defaultValue, null, '\t'), documentation: '' });
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public collectPropertySuggestions(resource: string, location: JSONLocation, currentWord: string, addValue: boolean, isLast:boolean, result: ISuggestionsCollector) : Thenable<any> {
|
||||
if (this.isPackageJSONFile(resource) && (location.matches(['dependencies']) || location.matches(['devDependencies']) || location.matches(['optionalDependencies']) || location.matches(['peerDependencies']))) {
|
||||
let queryUrl : string;
|
||||
if (currentWord.length > 0) {
|
||||
queryUrl = 'https://skimdb.npmjs.com/registry/_design/app/_view/browseAll?group_level=1&limit=' + LIMIT + '&start_key=%5B%22' + encodeURIComponent(currentWord) + '%22%5D&end_key=%5B%22'+ encodeURIComponent(currentWord + 'z') + '%22,%7B%7D%5D';
|
||||
|
||||
return this.requestService({
|
||||
url : queryUrl
|
||||
}).then((success) => {
|
||||
if (success.status === 200) {
|
||||
try {
|
||||
let obj = JSON.parse(success.responseText);
|
||||
if (obj && Array.isArray(obj.rows)) {
|
||||
let results = <{ key: string[]; }[]> obj.rows;
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
let keys = results[i].key;
|
||||
if (Array.isArray(keys) && keys.length > 0) {
|
||||
let name = keys[0];
|
||||
let insertText = JSON.stringify(name);
|
||||
if (addValue) {
|
||||
insertText += ': "{{*}}"';
|
||||
if (!isLast) {
|
||||
insertText += ',';
|
||||
}
|
||||
}
|
||||
result.add({ kind: CompletionItemKind.Property, label: name, insertText: insertText, documentation: '' });
|
||||
}
|
||||
}
|
||||
if (results.length === LIMIT) {
|
||||
result.setAsIncomplete();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
} else {
|
||||
result.error(nls.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));
|
||||
return 0;
|
||||
});
|
||||
} else {
|
||||
this.mostDependedOn.forEach((name) => {
|
||||
let insertText = JSON.stringify(name);
|
||||
if (addValue) {
|
||||
insertText += ': "{{*}}"';
|
||||
if (!isLast) {
|
||||
insertText += ',';
|
||||
}
|
||||
}
|
||||
result.add({ kind: CompletionItemKind.Property, label: name, insertText: insertText, documentation: '' });
|
||||
});
|
||||
result.setAsIncomplete();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public collectValueSuggestions(resource: string, location: JSONLocation, currentKey: string, result: ISuggestionsCollector): Thenable<any> {
|
||||
if (this.isPackageJSONFile(resource) && (location.matches(['dependencies']) || location.matches(['devDependencies']) || location.matches(['optionalDependencies']) || location.matches(['peerDependencies']))) {
|
||||
let queryUrl = 'http://registry.npmjs.org/' + encodeURIComponent(currentKey) + '/latest';
|
||||
|
||||
return this.requestService({
|
||||
url : queryUrl
|
||||
}).then((success) => {
|
||||
try {
|
||||
let obj = JSON.parse(success.responseText);
|
||||
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') });
|
||||
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)') });
|
||||
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)') });
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
return 0;
|
||||
}, (error) => {
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public getInfoContribution(resource: string, location: JSONLocation): Thenable<MarkedString[]> {
|
||||
if (this.isPackageJSONFile(resource) && (location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']) || location.matches(['optionalDependencies', '*']) || location.matches(['peerDependencies', '*']))) {
|
||||
let pack = location.getSegments()[location.getSegments().length - 1];
|
||||
|
||||
let htmlContent : MarkedString[] = [];
|
||||
htmlContent.push(nls.localize('json.npm.package.hover', '{0}', pack));
|
||||
|
||||
let queryUrl = 'http://registry.npmjs.org/' + encodeURIComponent(pack) + '/latest';
|
||||
|
||||
return this.requestService({
|
||||
url : queryUrl
|
||||
}).then((success) => {
|
||||
try {
|
||||
let obj = JSON.parse(success.responseText);
|
||||
if (obj) {
|
||||
if (obj.description) {
|
||||
htmlContent.push(obj.description);
|
||||
}
|
||||
if (obj.version) {
|
||||
htmlContent.push(nls.localize('json.npm.version.hover', 'Latest version: {0}', obj.version));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
return htmlContent;
|
||||
}, (error) => {
|
||||
return htmlContent;
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import {MarkedString, CompletionItemKind, CompletionItem} 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';
|
||||
|
||||
let LIMIT = 40;
|
||||
|
||||
export class ProjectJSONContribution implements IJSONWorkerContribution {
|
||||
|
||||
private requestService : IRequestService;
|
||||
|
||||
public constructor(requestService: IRequestService) {
|
||||
this.requestService = requestService;
|
||||
}
|
||||
|
||||
private isProjectJSONFile(resource: string): boolean {
|
||||
return Strings.endsWith(resource, '/project.json');
|
||||
}
|
||||
|
||||
public collectDefaultSuggestions(resource: string, result: ISuggestionsCollector): Thenable<any> {
|
||||
if (this.isProjectJSONFile(resource)) {
|
||||
let defaultValue = {
|
||||
'version': '{{1.0.0-*}}',
|
||||
'dependencies': {},
|
||||
'frameworks': {
|
||||
'dnx451': {},
|
||||
'dnxcore50': {}
|
||||
}
|
||||
};
|
||||
result.add({ kind: CompletionItemKind.Class, label: nls.localize('json.project.default', 'Default project.json'), insertText: JSON.stringify(defaultValue, null, '\t'), documentation: '' });
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public collectPropertySuggestions(resource: string, location: JSONLocation, currentWord: string, addValue: boolean, isLast:boolean, result: ISuggestionsCollector) : Thenable<any> {
|
||||
if (this.isProjectJSONFile(resource) && (location.matches(['dependencies']) || location.matches(['frameworks', '*', 'dependencies']) || location.matches(['frameworks', '*', 'frameworkAssemblies']))) {
|
||||
let queryUrl : string;
|
||||
if (currentWord.length > 0) {
|
||||
queryUrl = 'https://www.nuget.org/api/v2/Packages?'
|
||||
+ '$filter=Id%20ge%20\''
|
||||
+ encodeURIComponent(currentWord)
|
||||
+ '\'%20and%20Id%20lt%20\''
|
||||
+ encodeURIComponent(currentWord + 'z')
|
||||
+ '\'%20and%20IsAbsoluteLatestVersion%20eq%20true'
|
||||
+ '&$select=Id,Version,Description&$format=json&$top=' + LIMIT;
|
||||
} else {
|
||||
queryUrl = 'https://www.nuget.org/api/v2/Packages?'
|
||||
+ '$filter=IsAbsoluteLatestVersion%20eq%20true'
|
||||
+ '&$orderby=DownloadCount%20desc&$top=' + LIMIT
|
||||
+ '&$select=Id,Version,DownloadCount,Description&$format=json';
|
||||
}
|
||||
|
||||
return this.requestService({
|
||||
url : queryUrl
|
||||
}).then((success) => {
|
||||
if (success.status === 200) {
|
||||
try {
|
||||
let obj = JSON.parse(success.responseText);
|
||||
if (Array.isArray(obj.d)) {
|
||||
let results = <any[]> obj.d;
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
let curr = results[i];
|
||||
let name = curr.Id;
|
||||
let version = curr.Version;
|
||||
if (name) {
|
||||
let documentation = curr.Description;
|
||||
let typeLabel = curr.Version;
|
||||
let insertText = JSON.stringify(name);
|
||||
if (addValue) {
|
||||
insertText += ': "{{' + version + '}}"';
|
||||
if (!isLast) {
|
||||
insertText += ',';
|
||||
}
|
||||
}
|
||||
result.add({ kind: CompletionItemKind.Property, label: name, insertText: insertText, detail: typeLabel, documentation: documentation });
|
||||
}
|
||||
}
|
||||
if (results.length === LIMIT) {
|
||||
result.setAsIncomplete();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
} else {
|
||||
result.error(nls.localize('json.nugget.error.repoaccess', 'Request to the nuget repository failed: {0}', success.responseText));
|
||||
return 0;
|
||||
}
|
||||
}, (error) => {
|
||||
result.error(nls.localize('json.nugget.error.repoaccess', 'Request to the nuget repository failed: {0}', error.responseText));
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public collectValueSuggestions(resource: string, location: JSONLocation, currentKey: string, result: ISuggestionsCollector): Thenable<any> {
|
||||
if (this.isProjectJSONFile(resource) && (location.matches(['dependencies']) || location.matches(['frameworks', '*', 'dependencies']) || location.matches(['frameworks', '*', 'frameworkAssemblies']))) {
|
||||
let queryUrl = 'https://www.myget.org/F/aspnetrelease/api/v2/Packages?'
|
||||
+ '$filter=Id%20eq%20\''
|
||||
+ encodeURIComponent(currentKey)
|
||||
+ '\'&$select=Version,IsAbsoluteLatestVersion&$format=json&$top=' + LIMIT;
|
||||
|
||||
return this.requestService({
|
||||
url : queryUrl
|
||||
}).then((success) => {
|
||||
try {
|
||||
let obj = JSON.parse(success.responseText);
|
||||
if (Array.isArray(obj.d)) {
|
||||
let results = <any[]> obj.d;
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
let curr = results[i];
|
||||
let version = curr.Version;
|
||||
if (version) {
|
||||
let name = JSON.stringify(version);
|
||||
let isLatest = curr.IsAbsoluteLatestVersion === 'true';
|
||||
let label = name;
|
||||
let documentation = '';
|
||||
if (isLatest) {
|
||||
documentation = nls.localize('json.nugget.versiondescription.suggest', 'The currently latest version of the package');
|
||||
}
|
||||
result.add({ kind: CompletionItemKind.Class, label: label, insertText: name, documentation: documentation });
|
||||
}
|
||||
}
|
||||
if (results.length === LIMIT) {
|
||||
result.setAsIncomplete();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
return 0;
|
||||
}, (error) => {
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public getInfoContribution(resource: string, location: JSONLocation): Thenable<MarkedString[]> {
|
||||
if (this.isProjectJSONFile(resource) && (location.matches(['dependencies', '*']) || location.matches(['frameworks', '*', 'dependencies', '*']) || location.matches(['frameworks', '*', 'frameworkAssemblies', '*']))) {
|
||||
let pack = location.getSegments()[location.getSegments().length - 1];
|
||||
|
||||
let htmlContent : MarkedString[] = [];
|
||||
htmlContent.push(nls.localize('json.nugget.package.hover', '{0}', pack));
|
||||
|
||||
let queryUrl = 'https://www.myget.org/F/aspnetrelease/api/v2/Packages?'
|
||||
+ '$filter=Id%20eq%20\''
|
||||
+ encodeURIComponent(pack)
|
||||
+ '\'%20and%20IsAbsoluteLatestVersion%20eq%20true'
|
||||
+ '&$select=Version,Description&$format=json&$top=5';
|
||||
|
||||
return this.requestService({
|
||||
url : queryUrl
|
||||
}).then((success) => {
|
||||
let content = success.responseText;
|
||||
if (content) {
|
||||
try {
|
||||
let obj = JSON.parse(content);
|
||||
if (obj.d && obj.d[0]) {
|
||||
let res = obj.d[0];
|
||||
if (res.Description) {
|
||||
htmlContent.push(res.Description);
|
||||
}
|
||||
if (res.Version) {
|
||||
htmlContent.push(nls.localize('json.nugget.version.hover', 'Latest version: {0}', res.Version));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return htmlContent;
|
||||
}, (error) => {
|
||||
return htmlContent;
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user