mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 12:19:20 +00:00
update to jsonc-parser 0.2.0
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
"dependencies": {
|
||||
"vscode-nls": "^1.0.4",
|
||||
"request-light": "^0.1.0",
|
||||
"jsonc-parser": "^0.1.0"
|
||||
"jsonc-parser": "^0.2.0"
|
||||
},
|
||||
"scripts": {
|
||||
"compile": "gulp compile-extension:javascript",
|
||||
|
||||
@@ -162,15 +162,17 @@ export class BowerJSONContribution implements IJSONContribution {
|
||||
|
||||
public getInfoContribution(resource: string, location: Location): Thenable<MarkedString[]> {
|
||||
if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']))) {
|
||||
let pack = location.segments[location.segments.length - 1];
|
||||
let htmlContent : MarkedString[] = [];
|
||||
htmlContent.push(localize('json.bower.package.hover', '{0}', pack));
|
||||
return this.getInfo(pack).then(documentation => {
|
||||
if (documentation) {
|
||||
htmlContent.push(documentation);
|
||||
}
|
||||
return htmlContent;
|
||||
});
|
||||
let pack = location.path[location.path.length - 1];
|
||||
if (typeof pack === 'string') {
|
||||
let htmlContent : MarkedString[] = [];
|
||||
htmlContent.push(localize('json.bower.package.hover', '{0}', pack));
|
||||
return this.getInfo(pack).then(documentation => {
|
||||
if (documentation) {
|
||||
htmlContent.push(documentation);
|
||||
}
|
||||
return htmlContent;
|
||||
});
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ export class JSONCompletionItemProvider implements CompletionItemProvider {
|
||||
|
||||
let collectPromise : Thenable<any> = null;
|
||||
|
||||
if (location.completeProperty) {
|
||||
if (location.isAtPropertyKey) {
|
||||
let addValue = !location.previousNode || !location.previousNode.columnOffset;
|
||||
let scanner = createScanner(document.getText(), true);
|
||||
scanner.setPosition(offset);
|
||||
@@ -128,7 +128,7 @@ export class JSONCompletionItemProvider implements CompletionItemProvider {
|
||||
let isLast = scanner.getToken() === SyntaxKind.CloseBraceToken || scanner.getToken() === SyntaxKind.EOF;
|
||||
collectPromise = this.jsonContribution.collectPropertySuggestions(fileName, location, currentWord, addValue, isLast, collector);
|
||||
} else {
|
||||
if (location.segments.length === 0) {
|
||||
if (location.path.length === 0) {
|
||||
collectPromise = this.jsonContribution.collectDefaultSuggestions(fileName, collector);
|
||||
} else {
|
||||
collectPromise = this.jsonContribution.collectValueSuggestions(fileName, location, collector);
|
||||
|
||||
@@ -117,44 +117,45 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
|
||||
public collectValueSuggestions(fileName: string, location: Location, result: ISuggestionsCollector): Thenable<any> {
|
||||
if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']) || location.matches(['optionalDependencies', '*']) || location.matches(['peerDependencies', '*']))) {
|
||||
let currentKey = location.segments[location.segments.length - 1];
|
||||
let queryUrl = 'http://registry.npmjs.org/' + encodeURIComponent(currentKey) + '/latest';
|
||||
let currentKey = location.path[location.path.length - 1];
|
||||
if (typeof currentKey === 'string') {
|
||||
let queryUrl = 'http://registry.npmjs.org/' + encodeURIComponent(currentKey) + '/latest';
|
||||
return this.xhr({
|
||||
url : queryUrl
|
||||
}).then((success) => {
|
||||
try {
|
||||
let obj = JSON.parse(success.responseText);
|
||||
if (obj && obj.version) {
|
||||
let version = obj.version;
|
||||
let name = JSON.stringify(version);
|
||||
let proposal = new CompletionItem(name);
|
||||
proposal.kind = CompletionItemKind.Property;
|
||||
proposal.insertText = name;
|
||||
proposal.documentation = localize('json.npm.latestversion', 'The currently latest version of the package');
|
||||
result.add(proposal);
|
||||
|
||||
return this.xhr({
|
||||
url : queryUrl
|
||||
}).then((success) => {
|
||||
try {
|
||||
let obj = JSON.parse(success.responseText);
|
||||
if (obj && obj.version) {
|
||||
let version = obj.version;
|
||||
let name = JSON.stringify(version);
|
||||
let proposal = new CompletionItem(name);
|
||||
proposal.kind = CompletionItemKind.Property;
|
||||
proposal.insertText = name;
|
||||
proposal.documentation = localize('json.npm.latestversion', 'The currently latest version of the package');
|
||||
result.add(proposal);
|
||||
name = JSON.stringify('^' + version);
|
||||
proposal = new CompletionItem(name);
|
||||
proposal.kind = CompletionItemKind.Property;
|
||||
proposal.insertText = name;
|
||||
proposal.documentation = localize('json.npm.majorversion', 'Matches the most recent major version (1.x.x)');
|
||||
result.add(proposal);
|
||||
|
||||
name = JSON.stringify('^' + version);
|
||||
proposal = new CompletionItem(name);
|
||||
proposal.kind = CompletionItemKind.Property;
|
||||
proposal.insertText = name;
|
||||
proposal.documentation = localize('json.npm.majorversion', 'Matches the most recent major version (1.x.x)');
|
||||
result.add(proposal);
|
||||
|
||||
name = JSON.stringify('~' + version);
|
||||
proposal = new CompletionItem(name);
|
||||
proposal.kind = CompletionItemKind.Property;
|
||||
proposal.insertText = name;
|
||||
proposal.documentation = localize('json.npm.minorversion', 'Matches the most recent minor version (1.2.x)');
|
||||
result.add(proposal);
|
||||
name = JSON.stringify('~' + version);
|
||||
proposal = new CompletionItem(name);
|
||||
proposal.kind = CompletionItemKind.Property;
|
||||
proposal.insertText = name;
|
||||
proposal.documentation = localize('json.npm.minorversion', 'Matches the most recent minor version (1.2.x)');
|
||||
result.add(proposal);
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
return 0;
|
||||
}, (error) => {
|
||||
return 0;
|
||||
});
|
||||
return 0;
|
||||
}, (error) => {
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -204,16 +205,17 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
|
||||
public getInfoContribution(fileName: string, location: Location): Thenable<MarkedString[]> {
|
||||
if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']) || location.matches(['optionalDependencies', '*']) || location.matches(['peerDependencies', '*']))) {
|
||||
let pack = location.segments[location.segments.length - 1];
|
||||
|
||||
let htmlContent : MarkedString[] = [];
|
||||
htmlContent.push(localize('json.npm.package.hover', '{0}', pack));
|
||||
return this.getInfo(pack).then(infos => {
|
||||
infos.forEach(info => {
|
||||
htmlContent.push(info);
|
||||
let pack = location.path[location.path.length - 1];
|
||||
if (typeof pack === 'string') {
|
||||
let htmlContent : MarkedString[] = [];
|
||||
htmlContent.push(localize('json.npm.package.hover', '{0}', pack));
|
||||
return this.getInfo(pack).then(infos => {
|
||||
infos.forEach(info => {
|
||||
htmlContent.push(info);
|
||||
});
|
||||
return htmlContent;
|
||||
});
|
||||
return htmlContent;
|
||||
});
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user