mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
auto-fixed prefer-const violation
This commit is contained in:
@@ -10,15 +10,15 @@ import phpGlobalFunctions = require('./phpGlobalFunctions');
|
||||
export default class PHPCompletionItemProvider implements CompletionItemProvider {
|
||||
|
||||
public provideCompletionItems(document: TextDocument, position: Position, _token: CancellationToken, context: CompletionContext): Promise<CompletionItem[]> {
|
||||
let result: CompletionItem[] = [];
|
||||
const result: CompletionItem[] = [];
|
||||
|
||||
let shouldProvideCompletionItems = workspace.getConfiguration('php').get<boolean>('suggest.basic', true);
|
||||
const shouldProvideCompletionItems = workspace.getConfiguration('php').get<boolean>('suggest.basic', true);
|
||||
if (!shouldProvideCompletionItems) {
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
||||
let range = document.getWordRangeAtPosition(position);
|
||||
let prefix = range ? document.getText(range) : '';
|
||||
const prefix = range ? document.getText(range) : '';
|
||||
if (!range) {
|
||||
range = new Range(position, position);
|
||||
}
|
||||
@@ -31,9 +31,9 @@ export default class PHPCompletionItemProvider implements CompletionItemProvider
|
||||
}
|
||||
}
|
||||
|
||||
let added: any = {};
|
||||
let createNewProposal = function (kind: CompletionItemKind, name: string, entry: phpGlobals.IEntry | null): CompletionItem {
|
||||
let proposal: CompletionItem = new CompletionItem(name);
|
||||
const added: any = {};
|
||||
const createNewProposal = function (kind: CompletionItemKind, name: string, entry: phpGlobals.IEntry | null): CompletionItem {
|
||||
const proposal: CompletionItem = new CompletionItem(name);
|
||||
proposal.kind = kind;
|
||||
if (entry) {
|
||||
if (entry.description) {
|
||||
@@ -46,63 +46,63 @@ export default class PHPCompletionItemProvider implements CompletionItemProvider
|
||||
return proposal;
|
||||
};
|
||||
|
||||
let matches = (name: string) => {
|
||||
const matches = (name: string) => {
|
||||
return prefix.length === 0 || name.length >= prefix.length && name.substr(0, prefix.length) === prefix;
|
||||
};
|
||||
|
||||
if (matches('php') && range.start.character >= 2) {
|
||||
let twoBeforePosition = new Position(range.start.line, range.start.character - 2);
|
||||
let beforeWord = document.getText(new Range(twoBeforePosition, range.start));
|
||||
const twoBeforePosition = new Position(range.start.line, range.start.character - 2);
|
||||
const beforeWord = document.getText(new Range(twoBeforePosition, range.start));
|
||||
|
||||
if (beforeWord === '<?') {
|
||||
let proposal = createNewProposal(CompletionItemKind.Class, '<?php', null);
|
||||
const proposal = createNewProposal(CompletionItemKind.Class, '<?php', null);
|
||||
proposal.textEdit = new TextEdit(new Range(twoBeforePosition, position), '<?php');
|
||||
result.push(proposal);
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
}
|
||||
|
||||
for (let globalvariables in phpGlobals.globalvariables) {
|
||||
for (const globalvariables in phpGlobals.globalvariables) {
|
||||
if (phpGlobals.globalvariables.hasOwnProperty(globalvariables) && matches(globalvariables)) {
|
||||
added[globalvariables] = true;
|
||||
result.push(createNewProposal(CompletionItemKind.Variable, globalvariables, phpGlobals.globalvariables[globalvariables]));
|
||||
}
|
||||
}
|
||||
for (let globalfunctions in phpGlobalFunctions.globalfunctions) {
|
||||
for (const globalfunctions in phpGlobalFunctions.globalfunctions) {
|
||||
if (phpGlobalFunctions.globalfunctions.hasOwnProperty(globalfunctions) && matches(globalfunctions)) {
|
||||
added[globalfunctions] = true;
|
||||
result.push(createNewProposal(CompletionItemKind.Function, globalfunctions, phpGlobalFunctions.globalfunctions[globalfunctions]));
|
||||
}
|
||||
}
|
||||
for (let compiletimeconstants in phpGlobals.compiletimeconstants) {
|
||||
for (const compiletimeconstants in phpGlobals.compiletimeconstants) {
|
||||
if (phpGlobals.compiletimeconstants.hasOwnProperty(compiletimeconstants) && matches(compiletimeconstants)) {
|
||||
added[compiletimeconstants] = true;
|
||||
result.push(createNewProposal(CompletionItemKind.Field, compiletimeconstants, phpGlobals.compiletimeconstants[compiletimeconstants]));
|
||||
}
|
||||
}
|
||||
for (let keywords in phpGlobals.keywords) {
|
||||
for (const keywords in phpGlobals.keywords) {
|
||||
if (phpGlobals.keywords.hasOwnProperty(keywords) && matches(keywords)) {
|
||||
added[keywords] = true;
|
||||
result.push(createNewProposal(CompletionItemKind.Keyword, keywords, phpGlobals.keywords[keywords]));
|
||||
}
|
||||
}
|
||||
|
||||
let text = document.getText();
|
||||
const text = document.getText();
|
||||
if (prefix[0] === '$') {
|
||||
let variableMatch = /\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/g;
|
||||
const variableMatch = /\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/g;
|
||||
let match: RegExpExecArray | null = null;
|
||||
while (match = variableMatch.exec(text)) {
|
||||
let word = match[0];
|
||||
const word = match[0];
|
||||
if (!added[word]) {
|
||||
added[word] = true;
|
||||
result.push(createNewProposal(CompletionItemKind.Variable, word, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
let functionMatch = /function\s+([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\s*\(/g;
|
||||
const functionMatch = /function\s+([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\s*\(/g;
|
||||
let match2: RegExpExecArray | null = null;
|
||||
while (match2 = functionMatch.exec(text)) {
|
||||
let word2 = match2[1];
|
||||
const word2 = match2[1];
|
||||
if (!added[word2]) {
|
||||
added[word2] = true;
|
||||
result.push(createNewProposal(CompletionItemKind.Function, word2, null));
|
||||
|
||||
@@ -11,22 +11,22 @@ import phpGlobalFunctions = require('./phpGlobalFunctions');
|
||||
export default class PHPHoverProvider implements HoverProvider {
|
||||
|
||||
public provideHover(document: TextDocument, position: Position, _token: CancellationToken): Hover | undefined {
|
||||
let enable = workspace.getConfiguration('php').get<boolean>('suggest.basic', true);
|
||||
const enable = workspace.getConfiguration('php').get<boolean>('suggest.basic', true);
|
||||
if (!enable) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let wordRange = document.getWordRangeAtPosition(position);
|
||||
const wordRange = document.getWordRangeAtPosition(position);
|
||||
if (!wordRange) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let name = document.getText(wordRange);
|
||||
const name = document.getText(wordRange);
|
||||
|
||||
let entry = phpGlobalFunctions.globalfunctions[name] || phpGlobals.compiletimeconstants[name] || phpGlobals.globalvariables[name] || phpGlobals.keywords[name];
|
||||
const entry = phpGlobalFunctions.globalfunctions[name] || phpGlobals.compiletimeconstants[name] || phpGlobals.globalvariables[name] || phpGlobals.keywords[name];
|
||||
if (entry && entry.description) {
|
||||
let signature = name + (entry.signature || '');
|
||||
let contents: MarkedString[] = [textToMarkedString(entry.description), { language: 'php', value: signature }];
|
||||
const signature = name + (entry.signature || '');
|
||||
const contents: MarkedString[] = [textToMarkedString(entry.description), { language: 'php', value: signature }];
|
||||
return new Hover(contents, wordRange);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ class BackwardIterator {
|
||||
this.lineNumber = -1;
|
||||
return BOF;
|
||||
}
|
||||
let ch = this.line.charCodeAt(this.offset);
|
||||
const ch = this.line.charCodeAt(this.offset);
|
||||
this.offset--;
|
||||
return ch;
|
||||
}
|
||||
@@ -69,36 +69,36 @@ class BackwardIterator {
|
||||
export default class PHPSignatureHelpProvider implements SignatureHelpProvider {
|
||||
|
||||
public provideSignatureHelp(document: TextDocument, position: Position, _token: CancellationToken): Promise<SignatureHelp> | null {
|
||||
let enable = workspace.getConfiguration('php').get<boolean>('suggest.basic', true);
|
||||
const enable = workspace.getConfiguration('php').get<boolean>('suggest.basic', true);
|
||||
if (!enable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let iterator = new BackwardIterator(document, position.character - 1, position.line);
|
||||
const iterator = new BackwardIterator(document, position.character - 1, position.line);
|
||||
|
||||
let paramCount = this.readArguments(iterator);
|
||||
const paramCount = this.readArguments(iterator);
|
||||
if (paramCount < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let ident = this.readIdent(iterator);
|
||||
const ident = this.readIdent(iterator);
|
||||
if (!ident) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let entry = phpGlobalFunctions.globalfunctions[ident] || phpGlobals.keywords[ident];
|
||||
const entry = phpGlobalFunctions.globalfunctions[ident] || phpGlobals.keywords[ident];
|
||||
if (!entry || !entry.signature) {
|
||||
return null;
|
||||
}
|
||||
let paramsString = entry.signature.substring(0, entry.signature.lastIndexOf(')') + 1);
|
||||
let signatureInfo = new SignatureInformation(ident + paramsString, entry.description);
|
||||
const paramsString = entry.signature.substring(0, entry.signature.lastIndexOf(')') + 1);
|
||||
const signatureInfo = new SignatureInformation(ident + paramsString, entry.description);
|
||||
|
||||
let re = /\w*\s+\&?\$[\w_\.]+|void/g;
|
||||
const re = /\w*\s+\&?\$[\w_\.]+|void/g;
|
||||
let match: RegExpExecArray | null = null;
|
||||
while ((match = re.exec(paramsString)) !== null) {
|
||||
signatureInfo.parameters.push({ label: match[0], documentation: '' });
|
||||
}
|
||||
let ret = new SignatureHelp();
|
||||
const ret = new SignatureHelp();
|
||||
ret.signatures.push(signatureInfo);
|
||||
ret.activeSignature = 0;
|
||||
ret.activeParameter = Math.min(paramCount, signatureInfo.parameters.length - 1);
|
||||
@@ -111,7 +111,7 @@ export default class PHPSignatureHelpProvider implements SignatureHelpProvider {
|
||||
let curlyNesting = 0;
|
||||
let paramCount = 0;
|
||||
while (iterator.hasNext()) {
|
||||
let ch = iterator.next();
|
||||
const ch = iterator.next();
|
||||
switch (ch) {
|
||||
case _LParent:
|
||||
parentNesting--;
|
||||
@@ -156,7 +156,7 @@ export default class PHPSignatureHelpProvider implements SignatureHelpProvider {
|
||||
let identStarted = false;
|
||||
let ident = '';
|
||||
while (iterator.hasNext()) {
|
||||
let ch = iterator.next();
|
||||
const ch = iterator.next();
|
||||
if (!identStarted && (ch === _WSB || ch === _TAB || ch === _NL)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -44,10 +44,10 @@ export class Throttler<T> {
|
||||
this.queuedPromiseFactory = promiseFactory;
|
||||
|
||||
if (!this.queuedPromise) {
|
||||
let onComplete = () => {
|
||||
const onComplete = () => {
|
||||
this.queuedPromise = null;
|
||||
|
||||
let result = this.queue(this.queuedPromiseFactory!);
|
||||
const result = this.queue(this.queuedPromiseFactory!);
|
||||
this.queuedPromiseFactory = null;
|
||||
|
||||
return result;
|
||||
@@ -127,7 +127,7 @@ export class Delayer<T> {
|
||||
this.completionPromise = null;
|
||||
this.onResolve = null;
|
||||
|
||||
let result = this.task!();
|
||||
const result = this.task!();
|
||||
this.task = null;
|
||||
|
||||
return result;
|
||||
|
||||
@@ -10,7 +10,7 @@ import * as path from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
import { ThrottledDelayer } from './utils/async';
|
||||
import * as nls from 'vscode-nls';
|
||||
let localize = nls.loadMessageBundle();
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
const enum Setting {
|
||||
Run = 'php.validate.run',
|
||||
@@ -28,8 +28,8 @@ export class LineDecoder {
|
||||
}
|
||||
|
||||
public write(buffer: Buffer): string[] {
|
||||
let result: string[] = [];
|
||||
let value = this.remaining
|
||||
const result: string[] = [];
|
||||
const value = this.remaining
|
||||
? this.remaining + this.stringDecoder.write(buffer)
|
||||
: this.stringDecoder.write(buffer);
|
||||
|
||||
@@ -70,11 +70,11 @@ enum RunTrigger {
|
||||
}
|
||||
|
||||
namespace RunTrigger {
|
||||
export let strings = {
|
||||
export const strings = {
|
||||
onSave: 'onSave',
|
||||
onType: 'onType'
|
||||
};
|
||||
export let from = function (value: string): RunTrigger {
|
||||
export const from = function (value: string): RunTrigger {
|
||||
if (value === 'onType') {
|
||||
return RunTrigger.onType;
|
||||
} else {
|
||||
@@ -165,7 +165,7 @@ export default class PHPValidationProvider {
|
||||
}
|
||||
|
||||
if (vscode.workspace.isTrusted) {
|
||||
let key = textDocument.uri.toString();
|
||||
const key = textDocument.uri.toString();
|
||||
let delayer = this.delayers![key];
|
||||
if (!delayer) {
|
||||
delayer = new ThrottledDelayer<void>(this.config?.trigger === RunTrigger.onType ? 250 : 0);
|
||||
@@ -191,14 +191,14 @@ export default class PHPValidationProvider {
|
||||
return;
|
||||
}
|
||||
|
||||
let decoder = new LineDecoder();
|
||||
let diagnostics: vscode.Diagnostic[] = [];
|
||||
let processLine = (line: string) => {
|
||||
let matches = line.match(PHPValidationProvider.MatchExpression);
|
||||
const decoder = new LineDecoder();
|
||||
const diagnostics: vscode.Diagnostic[] = [];
|
||||
const processLine = (line: string) => {
|
||||
const matches = line.match(PHPValidationProvider.MatchExpression);
|
||||
if (matches) {
|
||||
let message = matches[1];
|
||||
let line = parseInt(matches[3]) - 1;
|
||||
let diagnostic: vscode.Diagnostic = new vscode.Diagnostic(
|
||||
const message = matches[1];
|
||||
const line = parseInt(matches[3]) - 1;
|
||||
const diagnostic: vscode.Diagnostic = new vscode.Diagnostic(
|
||||
new vscode.Range(line, 0, line, Number.MAX_VALUE),
|
||||
message
|
||||
);
|
||||
@@ -206,7 +206,7 @@ export default class PHPValidationProvider {
|
||||
}
|
||||
};
|
||||
|
||||
let options = (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders[0]) ? { cwd: vscode.workspace.workspaceFolders[0].uri.fsPath } : undefined;
|
||||
const options = (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders[0]) ? { cwd: vscode.workspace.workspaceFolders[0].uri.fsPath } : undefined;
|
||||
let args: string[];
|
||||
if (this.config!.trigger === RunTrigger.onSave) {
|
||||
args = PHPValidationProvider.FileArgs.slice(0);
|
||||
@@ -215,7 +215,7 @@ export default class PHPValidationProvider {
|
||||
args = PHPValidationProvider.BufferArgs;
|
||||
}
|
||||
try {
|
||||
let childProcess = cp.spawn(executable, args, options);
|
||||
const childProcess = cp.spawn(executable, args, options);
|
||||
childProcess.on('error', (error: Error) => {
|
||||
if (this.pauseValidation) {
|
||||
resolve();
|
||||
@@ -234,7 +234,7 @@ export default class PHPValidationProvider {
|
||||
decoder.write(data).forEach(processLine);
|
||||
});
|
||||
childProcess.stdout.on('end', () => {
|
||||
let line = decoder.end();
|
||||
const line = decoder.end();
|
||||
if (line) {
|
||||
processLine(line);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import PHPValidationProvider from './features/validationProvider';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext): any {
|
||||
|
||||
let validator = new PHPValidationProvider();
|
||||
const validator = new PHPValidationProvider();
|
||||
validator.activate(context.subscriptions);
|
||||
|
||||
// add providers
|
||||
|
||||
Reference in New Issue
Block a user