提交 6e8f6596 编写于 作者: M Martin Aeschlimann

update to jsonc-parser 0.2.0

上级 85f337ee
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
"dependencies": { "dependencies": {
"vscode-nls": "^1.0.4", "vscode-nls": "^1.0.4",
"request-light": "^0.1.0", "request-light": "^0.1.0",
"jsonc-parser": "^0.1.0" "jsonc-parser": "^0.2.0"
}, },
"scripts": { "scripts": {
"compile": "gulp compile-extension:javascript", "compile": "gulp compile-extension:javascript",
......
...@@ -162,15 +162,17 @@ export class BowerJSONContribution implements IJSONContribution { ...@@ -162,15 +162,17 @@ export class BowerJSONContribution implements IJSONContribution {
public getInfoContribution(resource: string, location: Location): Thenable<MarkedString[]> { public getInfoContribution(resource: string, location: Location): Thenable<MarkedString[]> {
if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']))) { if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']))) {
let pack = location.segments[location.segments.length - 1]; let pack = location.path[location.path.length - 1];
let htmlContent : MarkedString[] = []; if (typeof pack === 'string') {
htmlContent.push(localize('json.bower.package.hover', '{0}', pack)); let htmlContent : MarkedString[] = [];
return this.getInfo(pack).then(documentation => { htmlContent.push(localize('json.bower.package.hover', '{0}', pack));
if (documentation) { return this.getInfo(pack).then(documentation => {
htmlContent.push(documentation); if (documentation) {
} htmlContent.push(documentation);
return htmlContent; }
}); return htmlContent;
});
}
} }
return null; return null;
} }
......
...@@ -120,7 +120,7 @@ export class JSONCompletionItemProvider implements CompletionItemProvider { ...@@ -120,7 +120,7 @@ export class JSONCompletionItemProvider implements CompletionItemProvider {
let collectPromise : Thenable<any> = null; let collectPromise : Thenable<any> = null;
if (location.completeProperty) { if (location.isAtPropertyKey) {
let addValue = !location.previousNode || !location.previousNode.columnOffset; let addValue = !location.previousNode || !location.previousNode.columnOffset;
let scanner = createScanner(document.getText(), true); let scanner = createScanner(document.getText(), true);
scanner.setPosition(offset); scanner.setPosition(offset);
...@@ -128,7 +128,7 @@ export class JSONCompletionItemProvider implements CompletionItemProvider { ...@@ -128,7 +128,7 @@ export class JSONCompletionItemProvider implements CompletionItemProvider {
let isLast = scanner.getToken() === SyntaxKind.CloseBraceToken || scanner.getToken() === SyntaxKind.EOF; let isLast = scanner.getToken() === SyntaxKind.CloseBraceToken || scanner.getToken() === SyntaxKind.EOF;
collectPromise = this.jsonContribution.collectPropertySuggestions(fileName, location, currentWord, addValue, isLast, collector); collectPromise = this.jsonContribution.collectPropertySuggestions(fileName, location, currentWord, addValue, isLast, collector);
} else { } else {
if (location.segments.length === 0) { if (location.path.length === 0) {
collectPromise = this.jsonContribution.collectDefaultSuggestions(fileName, collector); collectPromise = this.jsonContribution.collectDefaultSuggestions(fileName, collector);
} else { } else {
collectPromise = this.jsonContribution.collectValueSuggestions(fileName, location, collector); collectPromise = this.jsonContribution.collectValueSuggestions(fileName, location, collector);
......
...@@ -117,44 +117,45 @@ export class PackageJSONContribution implements IJSONContribution { ...@@ -117,44 +117,45 @@ export class PackageJSONContribution implements IJSONContribution {
public collectValueSuggestions(fileName: string, location: Location, result: ISuggestionsCollector): Thenable<any> { public collectValueSuggestions(fileName: string, location: Location, result: ISuggestionsCollector): Thenable<any> {
if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']) || location.matches(['optionalDependencies', '*']) || location.matches(['peerDependencies', '*']))) { if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']) || location.matches(['optionalDependencies', '*']) || location.matches(['peerDependencies', '*']))) {
let currentKey = location.segments[location.segments.length - 1]; let currentKey = location.path[location.path.length - 1];
let queryUrl = 'http://registry.npmjs.org/' + encodeURIComponent(currentKey) + '/latest'; if (typeof currentKey === 'string') {
let queryUrl = 'http://registry.npmjs.org/' + encodeURIComponent(currentKey) + '/latest';
return this.xhr({ return this.xhr({
url : queryUrl url : queryUrl
}).then((success) => { }).then((success) => {
try { try {
let obj = JSON.parse(success.responseText); let obj = JSON.parse(success.responseText);
if (obj && obj.version) { if (obj && obj.version) {
let version = obj.version; let version = obj.version;
let name = JSON.stringify(version); let name = JSON.stringify(version);
let proposal = new CompletionItem(name); let proposal = new CompletionItem(name);
proposal.kind = CompletionItemKind.Property; proposal.kind = CompletionItemKind.Property;
proposal.insertText = name; proposal.insertText = name;
proposal.documentation = localize('json.npm.latestversion', 'The currently latest version of the package'); proposal.documentation = localize('json.npm.latestversion', 'The currently latest version of the package');
result.add(proposal); result.add(proposal);
name = JSON.stringify('^' + version); name = JSON.stringify('^' + version);
proposal = new CompletionItem(name); proposal = new CompletionItem(name);
proposal.kind = CompletionItemKind.Property; proposal.kind = CompletionItemKind.Property;
proposal.insertText = name; proposal.insertText = name;
proposal.documentation = localize('json.npm.majorversion', 'Matches the most recent major version (1.x.x)'); proposal.documentation = localize('json.npm.majorversion', 'Matches the most recent major version (1.x.x)');
result.add(proposal); result.add(proposal);
name = JSON.stringify('~' + version); name = JSON.stringify('~' + version);
proposal = new CompletionItem(name); proposal = new CompletionItem(name);
proposal.kind = CompletionItemKind.Property; proposal.kind = CompletionItemKind.Property;
proposal.insertText = name; proposal.insertText = name;
proposal.documentation = localize('json.npm.minorversion', 'Matches the most recent minor version (1.2.x)'); proposal.documentation = localize('json.npm.minorversion', 'Matches the most recent minor version (1.2.x)');
result.add(proposal); result.add(proposal);
}
} catch (e) {
// ignore
} }
} catch (e) { return 0;
// ignore }, (error) => {
} return 0;
return 0; });
}, (error) => { }
return 0;
});
} }
return null; return null;
} }
...@@ -204,16 +205,17 @@ export class PackageJSONContribution implements IJSONContribution { ...@@ -204,16 +205,17 @@ export class PackageJSONContribution implements IJSONContribution {
public getInfoContribution(fileName: string, location: Location): Thenable<MarkedString[]> { public getInfoContribution(fileName: string, location: Location): Thenable<MarkedString[]> {
if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']) || location.matches(['optionalDependencies', '*']) || location.matches(['peerDependencies', '*']))) { if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']) || location.matches(['optionalDependencies', '*']) || location.matches(['peerDependencies', '*']))) {
let pack = location.segments[location.segments.length - 1]; let pack = location.path[location.path.length - 1];
if (typeof pack === 'string') {
let htmlContent : MarkedString[] = []; let htmlContent : MarkedString[] = [];
htmlContent.push(localize('json.npm.package.hover', '{0}', pack)); htmlContent.push(localize('json.npm.package.hover', '{0}', pack));
return this.getInfo(pack).then(infos => { return this.getInfo(pack).then(infos => {
infos.forEach(info => { infos.forEach(info => {
htmlContent.push(info); htmlContent.push(info);
});
return htmlContent;
}); });
return htmlContent; }
});
} }
return null; return null;
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
}, },
"dependencies": { "dependencies": {
"request-light": "^0.1.0", "request-light": "^0.1.0",
"jsonc-parser": "^0.1.0", "jsonc-parser": "^0.2.0",
"vscode-languageserver": "^1.3.0", "vscode-languageserver": "^1.3.0",
"vscode-nls": "^1.0.4" "vscode-nls": "^1.0.4"
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册