mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 11:38:51 +01:00
Use const where ever possible in JS ext
This commit is contained in:
@@ -31,7 +31,7 @@ export class BowerJSONContribution implements IJSONContribution {
|
||||
}
|
||||
|
||||
public collectDefaultSuggestions(resource: string, collector: ISuggestionsCollector): Thenable<any> {
|
||||
let defaultValue = {
|
||||
const defaultValue = {
|
||||
'name': '${1:name}',
|
||||
'description': '${2:description}',
|
||||
'authors': ['${3:author}'],
|
||||
@@ -39,7 +39,7 @@ export class BowerJSONContribution implements IJSONContribution {
|
||||
'main': '${5:pathToMain}',
|
||||
'dependencies': {}
|
||||
};
|
||||
let proposal = new CompletionItem(localize('json.bower.default', 'Default bower.json'));
|
||||
const proposal = new CompletionItem(localize('json.bower.default', 'Default bower.json'));
|
||||
proposal.kind = CompletionItemKind.Class;
|
||||
proposal.insertText = new SnippetString(JSON.stringify(defaultValue, null, '\t'));
|
||||
collector.add(proposal);
|
||||
@@ -49,27 +49,27 @@ export class BowerJSONContribution implements IJSONContribution {
|
||||
public collectPropertySuggestions(resource: string, location: Location, currentWord: string, addValue: boolean, isLast: boolean, collector: ISuggestionsCollector): Thenable<any> | null {
|
||||
if ((location.matches(['dependencies']) || location.matches(['devDependencies']))) {
|
||||
if (currentWord.length > 0) {
|
||||
let queryUrl = 'https://bower.herokuapp.com/packages/search/' + encodeURIComponent(currentWord);
|
||||
const queryUrl = 'https://bower.herokuapp.com/packages/search/' + encodeURIComponent(currentWord);
|
||||
|
||||
return this.xhr({
|
||||
url: queryUrl
|
||||
}).then((success) => {
|
||||
if (success.status === 200) {
|
||||
try {
|
||||
let obj = JSON.parse(success.responseText);
|
||||
const obj = JSON.parse(success.responseText);
|
||||
if (Array.isArray(obj)) {
|
||||
let results = <{ name: string; description: string; }[]>obj;
|
||||
const 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 = new SnippetString().appendText(JSON.stringify(name));
|
||||
const name = results[i].name;
|
||||
const description = results[i].description || '';
|
||||
const insertText = new SnippetString().appendText(JSON.stringify(name));
|
||||
if (addValue) {
|
||||
insertText.appendText(': ').appendPlaceholder('latest');
|
||||
if (!isLast) {
|
||||
insertText.appendText(',');
|
||||
}
|
||||
}
|
||||
let proposal = new CompletionItem(name);
|
||||
const proposal = new CompletionItem(name);
|
||||
proposal.kind = CompletionItemKind.Property;
|
||||
proposal.insertText = insertText;
|
||||
proposal.filterText = JSON.stringify(name);
|
||||
@@ -91,7 +91,7 @@ export class BowerJSONContribution implements IJSONContribution {
|
||||
});
|
||||
} else {
|
||||
this.topRanked.forEach((name) => {
|
||||
let insertText = new SnippetString().appendText(JSON.stringify(name));
|
||||
const insertText = new SnippetString().appendText(JSON.stringify(name));
|
||||
if (addValue) {
|
||||
insertText.appendText(': ').appendPlaceholder('latest');
|
||||
if (!isLast) {
|
||||
@@ -99,7 +99,7 @@ export class BowerJSONContribution implements IJSONContribution {
|
||||
}
|
||||
}
|
||||
|
||||
let proposal = new CompletionItem(name);
|
||||
const proposal = new CompletionItem(name);
|
||||
proposal.kind = CompletionItemKind.Property;
|
||||
proposal.insertText = insertText;
|
||||
proposal.filterText = JSON.stringify(name);
|
||||
@@ -116,7 +116,7 @@ export class BowerJSONContribution implements IJSONContribution {
|
||||
public collectValueSuggestions(resource: string, location: Location, collector: ISuggestionsCollector): Thenable<any> {
|
||||
if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']))) {
|
||||
// not implemented. Could be do done calling the bower command. Waiting for web API: https://github.com/bower/registry/issues/26
|
||||
let proposal = new CompletionItem(localize('json.bower.latest.version', 'latest'));
|
||||
const proposal = new CompletionItem(localize('json.bower.latest.version', 'latest'));
|
||||
proposal.insertText = new SnippetString('"${1:latest}"');
|
||||
proposal.filterText = '""';
|
||||
proposal.kind = CompletionItemKind.Value;
|
||||
@@ -140,13 +140,13 @@ export class BowerJSONContribution implements IJSONContribution {
|
||||
}
|
||||
|
||||
private getInfo(pack: string): Thenable<string | undefined> {
|
||||
let queryUrl = 'https://bower.herokuapp.com/packages/' + encodeURIComponent(pack);
|
||||
const queryUrl = 'https://bower.herokuapp.com/packages/' + encodeURIComponent(pack);
|
||||
|
||||
return this.xhr({
|
||||
url: queryUrl
|
||||
}).then((success) => {
|
||||
try {
|
||||
let obj = JSON.parse(success.responseText);
|
||||
const obj = JSON.parse(success.responseText);
|
||||
if (obj && obj.url) {
|
||||
let url: string = obj.url;
|
||||
if (url.indexOf('git://') === 0) {
|
||||
@@ -168,7 +168,7 @@ export class BowerJSONContribution implements IJSONContribution {
|
||||
|
||||
public getInfoContribution(resource: string, location: Location): Thenable<MarkedString[] | null> | null {
|
||||
if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']))) {
|
||||
let pack = location.path[location.path.length - 1];
|
||||
const pack = location.path[location.path.length - 1];
|
||||
if (typeof pack === 'string') {
|
||||
return this.getInfo(pack).then(documentation => {
|
||||
if (documentation) {
|
||||
|
||||
@@ -32,10 +32,10 @@ export interface IJSONContribution {
|
||||
}
|
||||
|
||||
export function addJSONProviders(xhr: XHRRequest): Disposable {
|
||||
let contributions = [new PackageJSONContribution(xhr), new BowerJSONContribution(xhr)];
|
||||
let subscriptions: Disposable[] = [];
|
||||
const contributions = [new PackageJSONContribution(xhr), new BowerJSONContribution(xhr)];
|
||||
const subscriptions: Disposable[] = [];
|
||||
contributions.forEach(contribution => {
|
||||
let selector = contribution.getDocumentSelector();
|
||||
const selector = contribution.getDocumentSelector();
|
||||
subscriptions.push(languages.registerCompletionItemProvider(selector, new JSONCompletionItemProvider(contribution), '"', ':'));
|
||||
subscriptions.push(languages.registerHoverProvider(selector, new JSONHoverProvider(contribution)));
|
||||
});
|
||||
@@ -48,19 +48,19 @@ export class JSONHoverProvider implements HoverProvider {
|
||||
}
|
||||
|
||||
public provideHover(document: TextDocument, position: Position, token: CancellationToken): Thenable<Hover> | null {
|
||||
let fileName = basename(document.fileName);
|
||||
let offset = document.offsetAt(position);
|
||||
let location = getLocation(document.getText(), offset);
|
||||
const fileName = basename(document.fileName);
|
||||
const offset = document.offsetAt(position);
|
||||
const location = getLocation(document.getText(), offset);
|
||||
if (!location.previousNode) {
|
||||
return null;
|
||||
}
|
||||
const node = location.previousNode;
|
||||
if (node && node.offset <= offset && offset <= node.offset + node.length) {
|
||||
let promise = this.jsonContribution.getInfoContribution(fileName, location);
|
||||
const promise = this.jsonContribution.getInfoContribution(fileName, location);
|
||||
if (promise) {
|
||||
return promise.then(htmlContent => {
|
||||
let range = new Range(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
|
||||
let result: Hover = {
|
||||
const range = new Range(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
|
||||
const result: Hover = {
|
||||
contents: htmlContent || [],
|
||||
range: range
|
||||
};
|
||||
@@ -79,7 +79,7 @@ export class JSONCompletionItemProvider implements CompletionItemProvider {
|
||||
|
||||
public resolveCompletionItem(item: CompletionItem, token: CancellationToken): Thenable<CompletionItem | null> {
|
||||
if (this.jsonContribution.resolveSuggestion) {
|
||||
let resolver = this.jsonContribution.resolveSuggestion(item);
|
||||
const resolver = this.jsonContribution.resolveSuggestion(item);
|
||||
if (resolver) {
|
||||
return resolver;
|
||||
}
|
||||
@@ -89,26 +89,26 @@ export class JSONCompletionItemProvider implements CompletionItemProvider {
|
||||
|
||||
public provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken): Thenable<CompletionList | null> | null {
|
||||
|
||||
let fileName = basename(document.fileName);
|
||||
const fileName = basename(document.fileName);
|
||||
|
||||
let currentWord = this.getCurrentWord(document, position);
|
||||
const currentWord = this.getCurrentWord(document, position);
|
||||
let overwriteRange: Range;
|
||||
|
||||
let items: CompletionItem[] = [];
|
||||
const items: CompletionItem[] = [];
|
||||
let isIncomplete = false;
|
||||
|
||||
let offset = document.offsetAt(position);
|
||||
let location = getLocation(document.getText(), offset);
|
||||
const offset = document.offsetAt(position);
|
||||
const location = getLocation(document.getText(), offset);
|
||||
|
||||
let node = location.previousNode;
|
||||
const node = location.previousNode;
|
||||
if (node && node.offset <= offset && offset <= node.offset + node.length && (node.type === 'property' || node.type === 'string' || node.type === 'number' || node.type === 'boolean' || node.type === 'null')) {
|
||||
overwriteRange = new Range(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
|
||||
} else {
|
||||
overwriteRange = new Range(document.positionAt(offset - currentWord.length), position);
|
||||
}
|
||||
|
||||
let proposed: { [key: string]: boolean } = {};
|
||||
let collector: ISuggestionsCollector = {
|
||||
const proposed: { [key: string]: boolean } = {};
|
||||
const collector: ISuggestionsCollector = {
|
||||
add: (suggestion: CompletionItem) => {
|
||||
if (!proposed[suggestion.label]) {
|
||||
proposed[suggestion.label] = true;
|
||||
@@ -124,8 +124,8 @@ export class JSONCompletionItemProvider implements CompletionItemProvider {
|
||||
let collectPromise: Thenable<any> | null = null;
|
||||
|
||||
if (location.isAtPropertyKey) {
|
||||
let addValue = !location.previousNode || !location.previousNode.columnOffset;
|
||||
let isLast = this.isLast(document, position);
|
||||
const addValue = !location.previousNode || !location.previousNode.columnOffset;
|
||||
const isLast = this.isLast(document, position);
|
||||
collectPromise = this.jsonContribution.collectPropertySuggestions(fileName, location, currentWord, addValue, isLast, collector);
|
||||
} else {
|
||||
if (location.path.length === 0) {
|
||||
@@ -146,8 +146,8 @@ export class JSONCompletionItemProvider implements CompletionItemProvider {
|
||||
}
|
||||
|
||||
private getCurrentWord(document: TextDocument, position: Position) {
|
||||
var i = position.character - 1;
|
||||
var text = document.lineAt(position.line).text;
|
||||
let i = position.character - 1;
|
||||
const text = document.lineAt(position.line).text;
|
||||
while (i >= 0 && ' \t\n\r\v":{[,'.indexOf(text.charAt(i)) === -1) {
|
||||
i--;
|
||||
}
|
||||
@@ -155,7 +155,7 @@ export class JSONCompletionItemProvider implements CompletionItemProvider {
|
||||
}
|
||||
|
||||
private isLast(document: TextDocument, position: Position): boolean {
|
||||
let scanner = createScanner(document.getText(), true);
|
||||
const scanner = createScanner(document.getText(), true);
|
||||
scanner.setPosition(document.offsetAt(position));
|
||||
let nextToken = scanner.scan();
|
||||
if (nextToken === SyntaxKind.StringLiteral && scanner.getTokenError() === ScanError.UnexpectedEndOfString) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import { textToMarkedString } from './markedTextUtil';
|
||||
import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
let LIMIT = 40;
|
||||
const LIMIT = 40;
|
||||
|
||||
export class PackageJSONContribution implements IJSONContribution {
|
||||
|
||||
@@ -32,7 +32,7 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
}
|
||||
|
||||
public collectDefaultSuggestions(fileName: string, result: ISuggestionsCollector): Thenable<any> {
|
||||
let defaultValue = {
|
||||
const defaultValue = {
|
||||
'name': '${1:name}',
|
||||
'description': '${2:description}',
|
||||
'authors': '${3:author}',
|
||||
@@ -40,7 +40,7 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
'main': '${5:pathToMain}',
|
||||
'dependencies': {}
|
||||
};
|
||||
let proposal = new CompletionItem(localize('json.package.default', 'Default package.json'));
|
||||
const proposal = new CompletionItem(localize('json.package.default', 'Default package.json'));
|
||||
proposal.kind = CompletionItemKind.Module;
|
||||
proposal.insertText = new SnippetString(JSON.stringify(defaultValue, null, '\t'));
|
||||
result.add(proposal);
|
||||
@@ -65,21 +65,21 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
}).then((success) => {
|
||||
if (success.status === 200) {
|
||||
try {
|
||||
let obj = JSON.parse(success.responseText);
|
||||
const obj = JSON.parse(success.responseText);
|
||||
if (obj && Array.isArray(obj.rows)) {
|
||||
let results = <{ key: string[]; }[]>obj.rows;
|
||||
const results = <{ key: string[]; }[]>obj.rows;
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
let keys = results[i].key;
|
||||
const keys = results[i].key;
|
||||
if (Array.isArray(keys) && keys.length > 0) {
|
||||
let name = keys[0];
|
||||
let insertText = new SnippetString().appendText(JSON.stringify(name));
|
||||
const name = keys[0];
|
||||
const insertText = new SnippetString().appendText(JSON.stringify(name));
|
||||
if (addValue) {
|
||||
insertText.appendText(': "').appendTabstop().appendText('"');
|
||||
if (!isLast) {
|
||||
insertText.appendText(',');
|
||||
}
|
||||
}
|
||||
let proposal = new CompletionItem(name);
|
||||
const proposal = new CompletionItem(name);
|
||||
proposal.kind = CompletionItemKind.Property;
|
||||
proposal.insertText = insertText;
|
||||
proposal.filterText = JSON.stringify(name);
|
||||
@@ -104,14 +104,14 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
});
|
||||
} else {
|
||||
this.mostDependedOn.forEach((name) => {
|
||||
let insertText = new SnippetString().appendText(JSON.stringify(name));
|
||||
const insertText = new SnippetString().appendText(JSON.stringify(name));
|
||||
if (addValue) {
|
||||
insertText.appendText(': "').appendTabstop().appendText('"');
|
||||
if (!isLast) {
|
||||
insertText.appendText(',');
|
||||
}
|
||||
}
|
||||
let proposal = new CompletionItem(name);
|
||||
const proposal = new CompletionItem(name);
|
||||
proposal.kind = CompletionItemKind.Property;
|
||||
proposal.insertText = insertText;
|
||||
proposal.filterText = JSON.stringify(name);
|
||||
@@ -131,15 +131,15 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
result: ISuggestionsCollector
|
||||
): Thenable<any> | null {
|
||||
if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']) || location.matches(['optionalDependencies', '*']) || location.matches(['peerDependencies', '*']))) {
|
||||
let currentKey = location.path[location.path.length - 1];
|
||||
const currentKey = location.path[location.path.length - 1];
|
||||
if (typeof currentKey === 'string') {
|
||||
let queryUrl = 'http://registry.npmjs.org/' + encodeURIComponent(currentKey).replace('%40', '@');
|
||||
const queryUrl = 'http://registry.npmjs.org/' + encodeURIComponent(currentKey).replace('%40', '@');
|
||||
return this.xhr({
|
||||
url: queryUrl
|
||||
}).then((success) => {
|
||||
try {
|
||||
let obj = JSON.parse(success.responseText);
|
||||
let latest = obj && obj['dist-tags'] && obj['dist-tags']['latest'];
|
||||
const obj = JSON.parse(success.responseText);
|
||||
const latest = obj && obj['dist-tags'] && obj['dist-tags']['latest'];
|
||||
if (latest) {
|
||||
let name = JSON.stringify(latest);
|
||||
let proposal = new CompletionItem(name);
|
||||
@@ -192,18 +192,18 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
|
||||
private getInfo(pack: string): Thenable<string[]> {
|
||||
|
||||
let queryUrl = 'http://registry.npmjs.org/' + encodeURIComponent(pack).replace('%40', '@');
|
||||
const queryUrl = 'http://registry.npmjs.org/' + encodeURIComponent(pack).replace('%40', '@');
|
||||
return this.xhr({
|
||||
url: queryUrl
|
||||
}).then((success) => {
|
||||
try {
|
||||
let obj = JSON.parse(success.responseText);
|
||||
const obj = JSON.parse(success.responseText);
|
||||
if (obj) {
|
||||
let result: string[] = [];
|
||||
const result: string[] = [];
|
||||
if (obj.description) {
|
||||
result.push(obj.description);
|
||||
}
|
||||
let latest = obj && obj['dist-tags'] && obj['dist-tags']['latest'];
|
||||
const latest = obj && obj['dist-tags'] && obj['dist-tags']['latest'];
|
||||
if (latest) {
|
||||
result.push(localize('json.npm.version.hover', 'Latest version: {0}', latest));
|
||||
}
|
||||
@@ -220,7 +220,7 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
|
||||
public getInfoContribution(fileName: string, location: Location): Thenable<MarkedString[] | null> | null {
|
||||
if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']) || location.matches(['optionalDependencies', '*']) || location.matches(['peerDependencies', '*']))) {
|
||||
let pack = location.path[location.path.length - 1];
|
||||
const pack = location.path[location.path.length - 1];
|
||||
if (typeof pack === 'string') {
|
||||
return this.getInfo(pack).then(infos => {
|
||||
if (infos.length) {
|
||||
|
||||
@@ -22,6 +22,6 @@ export function activate(context: ExtensionContext): any {
|
||||
}
|
||||
|
||||
function configureHttpRequest() {
|
||||
let httpSettings = workspace.getConfiguration('http');
|
||||
const httpSettings = workspace.getConfiguration('http');
|
||||
httpRequest.configure(httpSettings.get<string>('proxy', ''), httpSettings.get<boolean>('proxyStrictSSL', true));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user