diff --git a/src/adf.ts b/src/adf.ts index 19254e1..e34d137 100644 --- a/src/adf.ts +++ b/src/adf.ts @@ -111,14 +111,12 @@ export class ADFTools { let pFile = new FileProxy(bUri); if (await pFile.exists()) { sourceFullPath = bUri; - } else { + } else if (workspaceRootDir) { // file not exists - if (workspaceRootDir) { - sourceFullPath = Uri.file(path.join(workspaceRootDir.fsPath, bootBlockSourceFilename)); - pFile = new FileProxy(sourceFullPath); - if (!pFile.exists()) { - sourceFullPath = null; - } + sourceFullPath = Uri.file(path.join(workspaceRootDir.fsPath, bootBlockSourceFilename)); + pFile = new FileProxy(sourceFullPath); + if (!await pFile.exists()) { + sourceFullPath = null; } } if (sourceFullPath) { @@ -127,7 +125,7 @@ export class ADFTools { const vasmBuildProperties = { ...VASMCompiler.DEFAULT_BUILD_CONFIGURATION }; vasmBuildProperties.args = ["-m68000", "-Fbin"]; const results = await compiler.buildFile(vasmBuildProperties, sourceFullPath, true); - if (results && results[0]) { + if (results?.[0]) { const bootBlockDataFilename = results[0]; bootBlockFilename = bootBlockDataFilename.replace(".o", ".bb"); const bootBlockDataFilenameUri = Uri.file(bootBlockDataFilename); @@ -156,13 +154,11 @@ export class ADFTools { let rootSourceDirUri: Uri; if (!path.isAbsolute(rootSourceDir) && workspace.workspaceFolders) { rootSourceDirUri = Uri.file(path.join(workspace.workspaceFolders[0].uri.fsPath, rootSourceDir)); + } else if (workspace.workspaceFolders) { + const relativePath = path.relative(workspace.workspaceFolders[0].uri.fsPath, rootSourceDir); + rootSourceDirUri = Uri.file(path.join(workspace.workspaceFolders[0].uri.fsPath, relativePath)); } else { - if (workspace.workspaceFolders) { - const relativePath = path.relative(workspace.workspaceFolders[0].uri.fsPath, rootSourceDir); - rootSourceDirUri = Uri.file(path.join(workspace.workspaceFolders[0].uri.fsPath, relativePath)); - } else { - rootSourceDirUri = Uri.file(rootSourceDir); - } + rootSourceDirUri = Uri.file(rootSourceDir); } const sourceRootFileProxy = new FileProxy(rootSourceDirUri, true); files = await sourceRootFileProxy.findFiles(includes, excludes); @@ -275,7 +271,7 @@ export class ADFTools { if (workspaceRootDir) { rootPath = workspaceRootDir.fsPath; } - const stdout = await this.executor.runToolRetrieveStdout(args, rootPath, commandFilename, null, cancellationToken); + const stdout = await this.executor.runToolRetrieveStdout(args, rootPath, commandFilename, undefined, cancellationToken); if (stdout.indexOf("Done.") < 0) { throw new Error(stdout); } diff --git a/src/asmONE.ts b/src/asmONE.ts index 64da907..9b0ddda 100644 --- a/src/asmONE.ts +++ b/src/asmONE.ts @@ -14,7 +14,7 @@ export class AsmONE { rxAuto: RegExp; constructor() { - this.rxAuto = RegExp(".*AUTO.*", "gi"); + this.rxAuto = /.*AUTO.*/gi; } /** @@ -25,8 +25,8 @@ export class AsmONE { public async Auto(filesURI: Uri[], exeFile: Uri): Promise { try { let symbols = new Array(); - for (let i = 0; i < filesURI.length; i++) { - const src = filesURI[i].fsPath; + for (const element of filesURI) { + const src = element.fsPath; const autos = this.findAutos(src); if (0 === autos.length) { continue; @@ -58,7 +58,7 @@ export class AsmONE { for (const err of errToFilter) { if (err.severity.toUpperCase() === "WARNING") { // remove auto warning message - if (err.msgData.match(this.rxAuto)) { + if (RegExp(this.rxAuto).exec(err.msgData)) { continue; } } @@ -105,8 +105,8 @@ export class AsmONE { private async loadExeSymbols(exeFile: Uri): Promise { const symbols = new Array(); const hunks = await parseHunksFromFile(exeFile.fsPath); - for (let i = 0; i < hunks.length; i++) { - const hunk: Hunk = hunks[i]; + for (const element of hunks) { + const hunk: Hunk = element; if (!hunk.symbols) { continue; } @@ -129,9 +129,9 @@ export class AsmONE { private findExeOffset(dest: string, symbols: SourceSymbol[]): number { const offset = -1; - for (let i = 0; i < symbols.length; i++) { - if (dest === symbols[i].name) { - return symbols[i].offset; + for (const element of symbols) { + if (dest === element.name) { + return element.offset; } } return offset; diff --git a/src/color.ts b/src/color.ts index 323ce78..e332037 100644 --- a/src/color.ts +++ b/src/color.ts @@ -27,7 +27,7 @@ export class M86kColorProvider implements DocumentColorProvider { * @param token Cancellation token */ public provideColorPresentations( - color: Color, context: { document: TextDocument, range: Range }, token: CancellationToken): + color: Color, context: { document: TextDocument, range: Range }): ProviderResult { return [new ColorPresentation(this.formatColor(color, context.document.getText(context.range)))]; } @@ -82,6 +82,6 @@ export class M86kColorProvider implements DocumentColorProvider { * @param value Number to format */ private formatColorComponent(value: number): string { - return Math.round(value).toString(16).substr(0, 1); + return Math.round(value).toString(16).substring(0, 2); } } \ No newline at end of file diff --git a/src/completion.ts b/src/completion.ts index ae99dc8..ed4924b 100644 --- a/src/completion.ts +++ b/src/completion.ts @@ -14,7 +14,7 @@ export class M68kCompletionItemProvider implements vscode.CompletionItemProvider this.definitionHandler = definitionHandler; this.language = language; } - public async provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise { + public async provideCompletionItems(document: vscode.TextDocument, position: vscode.Position): Promise { let completions = new Array(); let range = document.getWordRangeAtPosition(position); const line = document.lineAt(position.line); @@ -38,7 +38,7 @@ export class M68kCompletionItemProvider implements vscode.CompletionItemProvider ); // Find previous global label for (let i = range.start.line; i >= 0; i--) { - const match = document.lineAt(i).text.match(/^(\w+)\b/); + const match = RegExp(/^(\w+)\b/).exec(document.lineAt(i).text); if (match) { prefix = match[0]; break; @@ -61,21 +61,19 @@ export class M68kCompletionItemProvider implements vscode.CompletionItemProvider if (isInData) { if (isMnemonic) { continue; - } else { - if (value.type === DocumentationType.REGISTER || value.type === DocumentationType.CPU_REGISTER) { - if (word[0] === word[0].toLowerCase()) { - label = label.toLowerCase() - } - kind = vscode.CompletionItemKind.Variable; - } else if (word.startsWith("_LVO")) { - label = "_LVO" + label; + } else if (value.type === DocumentationType.REGISTER || value.type === DocumentationType.CPU_REGISTER) { + if (word.startsWith(word[0].toLowerCase())) { + label = label.toLowerCase() } + kind = vscode.CompletionItemKind.Variable; + } else if (word.startsWith("_LVO")) { + label = "_LVO" + label; } } else { if (!isMnemonic) { continue; } - if (word[0] === word[0].toUpperCase()) { + if (word[0].startsWith(word[0].toUpperCase())) { label = label.toUpperCase() } } @@ -98,7 +96,7 @@ export class M68kCompletionItemProvider implements vscode.CompletionItemProvider const labels = this.definitionHandler.findLabelStartingWith(word); for (const [label, symbol] of labels.entries()) { const unPrefixed = label.substring(prefix.length); - const isLocalFQ = unPrefixed.match(/.\./); + const isLocalFQ = RegExp(/.\./).exec(unPrefixed); if (!labelsAdded.includes(label) && !isLocalFQ) { const kind = vscode.CompletionItemKind.Function; const completion = new vscode.CompletionItem(unPrefixed, kind); @@ -175,7 +173,7 @@ export class M68kCompletionItemProvider implements vscode.CompletionItemProvider let start = 0; if (range) { start = range.start.character; - while (start > 0 && !line.text.charAt(start - 1).match(/[\s'"/]/)) { + while (start > 0 && !RegExp(/[\s'"/]/).exec(line.text.charAt(start - 1))) { start--; } range = new vscode.Range( @@ -195,7 +193,7 @@ export class M68kCompletionItemProvider implements vscode.CompletionItemProvider let prefix = ""; let filter: string | undefined; if (length > 0) { - const typedPath = asmLine.data.substr(start, length); + const typedPath = asmLine.data.substring(start, start + length); // Get absolute or relative path let newParent = incDir.getRelativeFile(typedPath); @@ -212,12 +210,12 @@ export class M68kCompletionItemProvider implements vscode.CompletionItemProvider const pos = normalizedTypedPath.lastIndexOf("/"); if (pos !== -1) { // Typed path is a partial filename in a containing directory - const subPath = normalizedTypedPath.substr(0, Math.max(pos, 1)); + const subPath = normalizedTypedPath.substring(0, Math.max(pos, 1) + 1); // Get containing directory newParent = incDir.getRelativeFile(subPath); if (await newParent.exists() && await newParent.isDirectory()) { incDir = newParent; - filter = normalizedTypedPath.substr(pos + 1); + filter = normalizedTypedPath.substring(pos + 1); } else { // containing directory doesn't exist return []; @@ -257,11 +255,14 @@ export class M68kCompletionItemProvider implements vscode.CompletionItemProvider } private cleanAndReorder(completions: vscode.CompletionItem[]): vscode.CompletionItem[] { - const fileMap = new Map(); - for (const c of completions) { - fileMap.set(c.label.toString(), c); + const labelMap = new Map(); + + for (const completion of completions) { + const label = typeof completion.label === "string" + ? completion.label : completion.label.label + labelMap.set(label, completion); } - return Array.from(fileMap.values()); + return Array.from(labelMap.values()); } private async provideCompletionForIncludes(asmLine: ASMLine, document: vscode.TextDocument, position: vscode.Position): Promise { diff --git a/src/configVariables.ts b/src/configVariables.ts index b79a686..56baade 100644 --- a/src/configVariables.ts +++ b/src/configVariables.ts @@ -18,7 +18,7 @@ interface Context { * The built-in logic in vscode only applies to specific properties and is not currently exposed in the public API * https://github.com/Microsoft/vscode/issues/46471 * - * For now we need to re-create the behaviour in order to apply it to custom properties. + * For now we need to re-create the behavior in order to apply it to custom properties. * * Supported variables: * - ${env:Name} - environment variable @@ -118,36 +118,34 @@ export function substituteVariables( // Environment variables: str = str.replace(/\${env:(.*?)}/g, (variable) => { - const varName = variable.match(/\${env:(.*?)}/)?.[1]; + const varName = RegExp(/\${env:(.*?)}/).exec(variable)?.[1]; return varName ? environmentVariables[varName] ?? "" : ""; }); // Config keys: str = str.replace(/\${config:(.*?)}/g, (variable) => { - const varName = variable.match(/\${config:(.*?)}/)?.[1]; + const varName = RegExp(/\${config:(.*?)}/).exec(variable)?.[1]; return varName ? configuration.get(varName, "") : ""; }); // Custom variables // extensionResourcesFolder if (extensionState) { - const pattern = new RegExp("\\${extensionResourcesFolder}", "g"); + const pattern = /\${extensionResourcesFolder}/g; str = str.replace(pattern, extensionState.getResourcesPath() ?? ""); } // platformName - const pattern = new RegExp("\\${platformName}", "g"); + const pattern = /\${platformName}/g; str = str.replace(pattern, process.platform ?? ""); // Apply recursive replacements if enabled and string still contains any variables if ( recursive && - str.match( - new RegExp( - "\\${(" + - Object.keys(replacements).join("|") + - "|env:(.*?)|config:(.*?))}" - ) - ) + RegExp(new RegExp( + "\\${(" + + Object.keys(replacements).join("|") + + "|env:(.*?)|config:(.*?))}" + )).exec(str) ) { str = substituteVariables(str, recursive, ctx); } diff --git a/src/configurationHelper.ts b/src/configurationHelper.ts index 864db9d..ef9e361 100644 --- a/src/configurationHelper.ts +++ b/src/configurationHelper.ts @@ -32,7 +32,7 @@ export class ConfigurationHelper { * @return New value */ public static retrieveStringProperty(configuration: vscode.WorkspaceConfiguration, key: string, defaultValue: string): string { - const confValue = configuration.get(key); + const confValue = configuration.get(key); if (confValue) { return `${confValue}`; } diff --git a/src/definitionHandler.ts b/src/definitionHandler.ts index cc47bea..efe69bc 100644 --- a/src/definitionHandler.ts +++ b/src/definitionHandler.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/ban-types */ -import { Definition, SymbolInformation, DocumentSymbolProvider, DefinitionProvider, TextDocument, Position, CancellationToken, Location, Uri, ReferenceProvider, ReferenceContext, Range, window } from 'vscode'; +import { Definition, SymbolInformation, DocumentSymbolProvider, DefinitionProvider, TextDocument, Position, Location, Uri, ReferenceProvider, Range, window } from 'vscode'; import * as vscode from 'vscode'; import { SymbolFile, Symbol } from './symbols'; import { Calc } from './calc'; @@ -20,7 +20,7 @@ export class M68kDefinitionHandler implements DefinitionProvider, ReferenceProvi private xrefs = new Map(); private sortedVariablesNames = new Array(); - public async provideDocumentSymbols(document: TextDocument, token: CancellationToken): Promise { + public async provideDocumentSymbols(document: TextDocument): Promise { const symbolFile: void | SymbolFile = await this.scanFile(document.uri, document); const results = new Array(); if (symbolFile) { @@ -73,7 +73,7 @@ export class M68kDefinitionHandler implements DefinitionProvider, ReferenceProvi return results; } - public async provideDefinition(document: TextDocument, position: Position, token: CancellationToken): Promise { + public async provideDefinition(document: TextDocument, position: Position): Promise { const rg = document.getWordRangeAtPosition(position); if (rg) { await this.scanFile(document.uri, document); @@ -99,7 +99,7 @@ export class M68kDefinitionHandler implements DefinitionProvider, ReferenceProvi throw new Error("Definition not found"); } - public async provideReferences(document: TextDocument, position: Position, context: ReferenceContext, token: CancellationToken): Promise { + public async provideReferences(document: TextDocument, position: Position): Promise { const rg = document.getWordRangeAtPosition(position); if (rg) { await this.scanFile(document.uri, document); @@ -140,7 +140,7 @@ export class M68kDefinitionHandler implements DefinitionProvider, ReferenceProvi } } } - foundRegisters.sort(); + foundRegisters.sort((a: string, b: string) => a.localeCompare(b)); return foundRegisters; } @@ -367,7 +367,7 @@ export class M68kDefinitionHandler implements DefinitionProvider, ReferenceProvi if (v !== undefined) { let value = v.getValue(); if ((value !== undefined) && (value.length > 0)) { - if (value.match(/[A-Za-z_]*/)) { + if (RegExp(/[A-Za-z_]*/).exec(value)) { value = this.replaceVariablesInFormula(value); } } diff --git a/src/documentation.ts b/src/documentation.ts index 2eb807c..fac02dd 100644 --- a/src/documentation.ts +++ b/src/documentation.ts @@ -159,7 +159,7 @@ export interface DocumentationLazy { loadDescription(): Promise; } -export function isDocumentationLazy(el: any): el is DocumentationLazy { +export function isDocumentationLazy(el: unknown): el is DocumentationLazy { return (el as DocumentationLazy).loadDescription !== undefined; } diff --git a/src/execHelper.ts b/src/execHelper.ts index b286662..1664781 100644 --- a/src/execHelper.ts +++ b/src/execHelper.ts @@ -33,17 +33,18 @@ export class ExecutorHelper { * @param parser Parser for the output * @param logEmitter Log event emitter */ - runTool(args: string[], cwd: string | null, severity: string, useStdErr: boolean, cmd: string, env: any, printUnexpectedOutput: boolean, parser: ExecutorParser | null, token?: vscode.CancellationToken, logEmitter?: vscode.EventEmitter): Promise { + runTool(args: string[], cwd: string | null, severity: string, useStdErr: boolean, cmd: string, env: NodeJS.ProcessEnv | undefined, printUnexpectedOutput: boolean, parser: ExecutorParser | null, token?: vscode.CancellationToken, logEmitter?: vscode.EventEmitter): Promise { return new Promise((resolve, reject) => { - const options: any = { - env: env + const options: cp.ExecFileOptionsWithBufferEncoding = { + env: env, + encoding: null }; if (cwd) { options.cwd = cwd; } const p = cp.execFile(cmd, args, options, (err, stdout, stderr) => { try { - if (err && (err).code === 'ENOENT') { + if (err && err.code === 'ENOENT') { const errorMessage = `Cannot find ${cmd} : ${err.message}`; if (logEmitter) { logEmitter.fire(errorMessage + '\r\n'); @@ -100,7 +101,7 @@ export class ExecutorHelper { private addKillToCancellationToken(p: cp.ChildProcess, token?: vscode.CancellationToken) { if (token) { token.onCancellationRequested(() => { - if (p && p.pid) { + if (p?.pid) { this.killTree(p.pid); } }); @@ -115,19 +116,19 @@ export class ExecutorHelper { * @param env Environment variables * @param token Cancellation token */ - runToolRetrieveStdout(args: string[], cwd: string | null, cmd: string, env: any, token?: vscode.CancellationToken): Promise { + runToolRetrieveStdout(args: string[], cwd: string | null, cmd: string, env: NodeJS.ProcessEnv | undefined, token?: vscode.CancellationToken): Promise { return new Promise((resolve, reject) => { - const options: any = { + const options: cp.ExecFileOptions = { env: env }; if (cwd) { options.cwd = cwd; } - const p = cp.execFile(cmd, args, options, (err, stdout, stderr) => { + const p = cp.execFile(cmd, args, options, (err, stdout) => { try { let bufferOut = ""; if (err) { - if ((err).code === 'ENOENT') { + if (err.code === 'ENOENT') { throw new Error(`Cannot find ${cmd}`); } else if (err.message) { bufferOut += err.message; @@ -152,7 +153,7 @@ export class ExecutorHelper { vscode.window.showErrorMessage(error.msg); } else { let canonicalFile; - if (document && document.fileName.endsWith(error.file)) { + if (document?.fileName.endsWith(error.file)) { canonicalFile = document.uri.toString(); } else { canonicalFile = vscode.Uri.file(error.file).toString(); @@ -312,7 +313,7 @@ export class ExecutorHelper { } // fall back to the first workspace const folders = vscode.workspace.workspaceFolders; - if (folders && folders.length) { + if (folders?.length) { return folders[0].uri.fsPath; } return "."; diff --git a/src/expressionDataGenerator.ts b/src/expressionDataGenerator.ts index f6aa417..0842963 100644 --- a/src/expressionDataGenerator.ts +++ b/src/expressionDataGenerator.ts @@ -292,7 +292,7 @@ export class ExpressionDataGeneratorSerializer { } export class DataGeneratorCodeLensProvider implements vscode.CodeLensProvider { - public provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken): + public provideCodeLenses(document: vscode.TextDocument): vscode.CodeLens[] | Thenable { // Search for start keyword const codeLensArray = new Array(); @@ -322,7 +322,7 @@ export class DataGeneratorCodeLensProvider implements vscode.CodeLensProvider { return rangesArray; } - public resolveCodeLens?(codeLens: vscode.CodeLens, token: vscode.CancellationToken): + public resolveCodeLens?(codeLens: vscode.CodeLens): vscode.CodeLens | Thenable { codeLens.command = { "command": "amiga-assembly.generate-data", @@ -336,7 +336,7 @@ export class DataGeneratorCodeLensProvider implements vscode.CodeLensProvider { public async onGenerateData(range: vscode.Range): Promise { const editor = vscode.window.activeTextEditor; if (editor) { - const edited = await editor.edit(async (edit) => { + const edited = await editor.edit((edit: vscode.TextEditorEdit) => { let rangesArray = new Array(); if (range) { rangesArray.push(range); diff --git a/src/extension.ts b/src/extension.ts index 016a9dd..8479a4c 100755 --- a/src/extension.ts +++ b/src/extension.ts @@ -117,7 +117,7 @@ export class ExtensionState { public static getCurrent(): ExtensionState { // activate the extension const ext = vscode.extensions.getExtension('prb28.amiga-assembly'); - if (ext && ext.exports && ext.exports.getState) { + if (ext?.exports?.getState) { return ext.exports.getState(); } return new ExtensionState(); @@ -225,7 +225,7 @@ export class ExtensionState { * Returns the temporary directory */ public getTmpDir(): FileProxy { - const tmpDirPath: any = ConfigurationHelper.retrieveStringPropertyInDefaultConf('tmpDir'); + const tmpDirPath: string | undefined = ConfigurationHelper.retrieveStringPropertyInDefaultConf('tmpDir'); if (tmpDirPath) { this.tmpDir = this.getPathOrRelative(tmpDirPath); } else { @@ -250,7 +250,7 @@ export class ExtensionState { if (this.forcedBuildDir) { return this.forcedBuildDir; } - const buildDirPath: any = ConfigurationHelper.retrieveStringPropertyInDefaultConf('buildDir'); + const buildDirPath: string | undefined = ConfigurationHelper.retrieveStringPropertyInDefaultConf('buildDir'); if (buildDirPath) { this.buildDir = this.getPathOrRelative(buildDirPath); } else { @@ -606,7 +606,7 @@ class FsUAEConfigurationProvider implements vscode.DebugConfigurationProvider { * Massage a debug configuration just before a debug session is being launched, * e.g. add all missing attributes to the debug configuration. */ - resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, token?: vscode.CancellationToken): vscode.ProviderResult { + resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration): vscode.ProviderResult { // if launch.json is missing or empty if (!config.type && !config.request && !config.name) { @@ -645,7 +645,7 @@ class InlineDebugAdapterFactory implements vscode.DebugAdapterDescriptorFactory // eslint-disable-next-line @typescript-eslint/no-unused-vars createDebugAdapterDescriptor(_session: vscode.DebugSession): vscode.ProviderResult { // since DebugAdapterInlineImplementation is proposed API, a cast to is required for now - return new vscode.DebugAdapterInlineImplementation(new DebugSession()); + return new vscode.DebugAdapterInlineImplementation(new DebugSession()); } } @@ -654,7 +654,7 @@ class RunFsUAEConfigurationProvider implements vscode.DebugConfigurationProvider * Massage a debug configuration just before a debug session is being launched, * e.g. add all missing attributes to the debug configuration. */ - async resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, token?: vscode.CancellationToken): Promise { + async resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration): Promise { // if launch.json is missing or empty if (!config.type && !config.request && !config.name) { const editor = vscode.window.activeTextEditor; @@ -682,9 +682,9 @@ class RunFsUAEConfigurationProvider implements vscode.DebugConfigurationProvider } class RunFsUAEInlineDebugAdapterFactory implements vscode.DebugAdapterDescriptorFactory { - createDebugAdapterDescriptor(_session: vscode.DebugSession): vscode.ProviderResult { + createDebugAdapterDescriptor(): vscode.ProviderResult { // since DebugAdapterInlineImplementation is proposed API, a cast to is required for now - return new vscode.DebugAdapterInlineImplementation(new DebugSession()); + return new vscode.DebugAdapterInlineImplementation(new DebugSession()); } } @@ -693,7 +693,7 @@ class WinUAEConfigurationProvider implements vscode.DebugConfigurationProvider { * Massage a debug configuration just before a debug session is being launched, * e.g. add all missing attributes to the debug configuration. */ - async resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, token?: vscode.CancellationToken): Promise { + async resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration): Promise { // if launch.json is missing or empty if (!config.type && !config.request && !config.name) { diff --git a/src/formatter.ts b/src/formatter.ts index ea1f86d..b236392 100644 --- a/src/formatter.ts +++ b/src/formatter.ts @@ -80,7 +80,7 @@ export class M68kFormatter implements vscode.DocumentFormattingEditProvider, vsc if (token.isCancellationRequested) { return []; } - edits = edits.concat(this.computeEditsForLine(asmDocument, asmLine, configuration)); + edits = edits.concat(this.computeEditsForLine(asmDocument, asmLine)); } return edits; } @@ -92,7 +92,7 @@ export class M68kFormatter implements vscode.DocumentFormattingEditProvider, vsc * @param configuration Configuration for the formatter * @return List of edits */ - public computeEditsForLine(asmDocument: ASMDocument, asmLine: ASMLine, configuration: DocumentFormatterConfiguration): vscode.TextEdit[] { + public computeEditsForLine(asmDocument: ASMDocument, asmLine: ASMLine): vscode.TextEdit[] { const edits = new Array(); if (!asmDocument.isOversized(asmLine)) { let range: vscode.Range; @@ -194,7 +194,7 @@ export class M68kFormatter implements vscode.DocumentFormattingEditProvider, vsc } } // Call standard format - edits = this.computeEditsForLine(asmDocument, asmLine, configuration); + edits = this.computeEditsForLine(asmDocument, asmLine); } return edits; } diff --git a/src/hover.ts b/src/hover.ts index 978dbfb..2642121 100644 --- a/src/hover.ts +++ b/src/hover.ts @@ -27,11 +27,11 @@ export class M68kHoverProvider implements vscode.HoverProvider { const line = document.lineAt(position.line); const asmLine = new ASMLine(line.text, line); // Detect where is the cursor - if (asmLine.instructionRange && asmLine.instructionRange.contains(position) && (asmLine.instruction.length > 0)) { + if (asmLine.instructionRange?.contains(position) && (asmLine.instruction.length > 0)) { let keyInstruction = asmLine.instruction; const idx = keyInstruction.indexOf('.'); if (idx > 0) { - keyInstruction = keyInstruction.substr(0, idx); + keyInstruction = keyInstruction.substring(0, idx); } if (!token.isCancellationRequested) { const [hoverInstruction, hoverDirective, macro] = await Promise.all([ @@ -39,7 +39,7 @@ export class M68kHoverProvider implements vscode.HoverProvider { this.documentationManager.getDirective(keyInstruction.toUpperCase()), definitionHandler.getMacroByName(keyInstruction) ]); - const hoverElement = hoverInstruction || hoverDirective + const hoverElement = hoverInstruction ?? hoverDirective if (hoverElement) { const hoverRendered = this.renderHover(hoverElement); return new vscode.Hover(hoverRendered, asmLine.instructionRange); @@ -56,7 +56,7 @@ export class M68kHoverProvider implements vscode.HoverProvider { return new vscode.Hover(contents, asmLine.instructionRange); } } - } else if (asmLine.dataRange && asmLine.dataRange.contains(position)) { + } else if (asmLine.dataRange?.contains(position)) { // get the word let word = document.getWordRangeAtPosition(position); let prefix = ""; @@ -69,7 +69,7 @@ export class M68kHoverProvider implements vscode.HoverProvider { ) // Find previous global label for (let i = word.start.line; i >= 0; i--) { - const match = document.lineAt(i).text.match(/^(\w+)\b/); + const match = RegExp(/^(\w+)\b/).exec(document.lineAt(i).text); if (match) { prefix = match[0]; break; @@ -89,7 +89,7 @@ export class M68kHoverProvider implements vscode.HoverProvider { if (cpuReg) { rendered = new vscode.MarkdownString(cpuReg.detail); } else if (label || xref) { - const symbol = label || xref; + const symbol = label ?? xref; const info = new vscode.MarkdownString(); info.appendCodeblock("(label) " + symbol?.getLabel()); const description = symbol?.getCommentBlock(); @@ -109,12 +109,12 @@ export class M68kHoverProvider implements vscode.HoverProvider { // Is there a value next to the register ? const elms = asmLine.data.split(","); for (const elm of elms) { - if (elm.match(/[$#%@]([\dA-F]+)/i)) { + if (RegExp(/[$#%@]([\dA-F]+)/i).exec(elm)) { renderedLine2 = this.renderRegisterValue(elm); if (renderedLine2) { break; } - } else if (elm.match(/[$#%@+-/*]([\dA-Z_]+)/i)) { + } else if (RegExp(/[$#%@+-/*]([\dA-Z_]+)/i).exec(elm)) { // Try to evaluate a formula // Evaluate the formula value try { diff --git a/src/iffImageViewer.ts b/src/iffImageViewer.ts index f993874..72ce798 100644 --- a/src/iffImageViewer.ts +++ b/src/iffImageViewer.ts @@ -22,7 +22,7 @@ export class IFFViewerPanel { // And restrict the webview to only loading content from our extension's `media` directory. const localResourceRoots = [vscode.Uri.file(path.join(extensionPath, IFFViewerPanel.SCRIPTS_PATH))]; const folders = vscode.workspace.workspaceFolders; - if (folders && folders.length) { + if (folders?.length) { for (const folder of folders) { localResourceRoots.push(folder.uri); } @@ -32,7 +32,7 @@ export class IFFViewerPanel { const panel = vscode.window.createWebviewPanel( IFFViewerPanel.VIEW_TYPE, 'IFF Viewer', - column || vscode.ViewColumn.One, + column ?? vscode.ViewColumn.One, { // Enable javascript in the webview enableScripts: true, @@ -63,7 +63,6 @@ export class IFFViewerPanel { message => { if (message.command === 'alert') { vscode.window.showErrorMessage(message.text); - return; } }, null, diff --git a/src/parser.ts b/src/parser.ts index 6b1b47f..672685c 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -98,7 +98,7 @@ export class ASMLine { current = next; } // To test the comment line the regexp needs an eol - if ((l.charAt(0) === ';') || (l.charAt(0) === '*')) { + if (l.startsWith(';') || l.startsWith('*')) { this.comment = l; this.commentRange = new Range(new Position(lineNumber, leadingSpacesCount), new Position(lineNumber, leadingSpacesCount + l.length)); this.lineType = ASMLineType.COMMENT; @@ -277,7 +277,7 @@ export class ASMLine { * @return true if it is an assignment */ public parseAssignment(line: string, lineNumber: number): boolean { - const regexp = /^([a-z0-9\-_]*)[\s]*(=|[\s][a-z]?equ(\.[a-z])?[\s])[\s]*(.*)/gi; + const regexp = /^([a-z0-9\-_]*)\s*(=|\s[a-z]?equ(\.[a-z])?\s)\s*(.*)/gi; const match = regexp.exec(line); if (match !== null) { this.variable = match[1].trim(); @@ -395,15 +395,13 @@ export class ASMLine { registers.push(r); } } - } else { - if (registers.indexOf(value) < 0) { - registers.push(value); - } + } else if (registers.indexOf(value) < 0) { + registers.push(value); } match = reg.exec(this.data); } } - return registers.sort(); + return registers.sort((a: string, b: string) => a.localeCompare(b)); } /** @@ -454,8 +452,8 @@ export class NumberParser { * @param word Word to parse */ public parseWithType(word: string): [number, NumberType] | null { - const hexValueRegExp = /[#]?\$([\da-z]+)/i; - const decValueRegExp = /[#]?([-]?[\d]+)/; + const hexValueRegExp = /#?\$([\da-z]+)/i; + const decValueRegExp = /#?(-?\d+)/; const octValueRegExp = /@(\d+)/; const binValueRegExp = /%([01]*)/; // look for an hex value @@ -663,7 +661,7 @@ export class ASMDocument { // Parse all the lines for (let i = localRange.start.line; i <= localRange.end.line; i++) { let isOversized = false; - if (token && token.isCancellationRequested) { + if (token?.isCancellationRequested) { return; } const line = document.lineAt(i); diff --git a/src/stringUtils.ts b/src/stringUtils.ts index 079b2a1..a22d69a 100644 --- a/src/stringUtils.ts +++ b/src/stringUtils.ts @@ -98,7 +98,7 @@ export class StringUtils { */ public static convertHexUTF8StringToUTF8(value: string): string { // split input into groups of two - const hex = value.match(/[\s\S]{2}/g) || []; + const hex = value.match(/[\s\S]{2}/g) ?? []; let output = ''; // build a hex-encoded representation of your string const j = hex.length; @@ -156,7 +156,7 @@ export class StringUtils { public static hexToBytes(hex: string): Array { const bytes = new Array(); for (let c = 0; c < hex.length; c += 2) { - bytes.push(parseInt(hex.substr(c, 2), 16)); + bytes.push(parseInt(hex.substring(c, c + 2), 16)); } return bytes; } @@ -166,8 +166,8 @@ export class StringUtils { **/ public static bytesToHex(bytes: Array): string { const hex = Array(); - for (let i = 0; i < bytes.length; i++) { - const current = bytes[i] < 0 ? bytes[i] + 256 : bytes[i]; + for (const element of bytes) { + const current = element < 0 ? element + 256 : element; hex.push((current >>> 4).toString(16)); hex.push((current & 0xF).toString(16)); } diff --git a/src/symbols.ts b/src/symbols.ts index 0c55c1b..7f67bc9 100644 --- a/src/symbols.ts +++ b/src/symbols.ts @@ -41,8 +41,8 @@ export class SymbolFile { this.definedSymbols.push(new Symbol(symbol, this, range)); } else { const results = asmLine.getSymbolFromData(); - for (let k = 0; k < results.length; k++) { - [symbol, range] = results[k]; + for (const element of results) { + [symbol, range] = element; if ((symbol !== undefined) && (range !== undefined)) { this.referredSymbols.push(new Symbol(symbol, this, range)); } @@ -51,13 +51,13 @@ export class SymbolFile { const instruct = asmLine.instruction.toLowerCase(); if (asmLine.label.length > 0) { let label = asmLine.label.replace(":", ""); - const isLocal = label.indexOf(".") === 0; + const isLocal = label.startsWith("."); if (isLocal) { label = lastLabel?.getLabel() + label; } const s = new Symbol(label, this, asmLine.labelRange); // Is this actually a macro definition in ` macro` syntax? - if (instruct.indexOf("macro") === 0) { + if (instruct.startsWith("macro")) { this.macros.push(s); this.definedSymbols.push(s); } else { @@ -66,11 +66,11 @@ export class SymbolFile { lastLabel = s; } } - } else if (instruct.indexOf("xref") === 0) { + } else if (instruct.startsWith("xref")) { const s = new Symbol(asmLine.data, this, asmLine.dataRange); this.xrefs.push(s); this.definedSymbols.push(s); - } else if (instruct.indexOf("macro") === 0) { + } else if (instruct.startsWith("macro")) { // Handle ` macro ` syntax const s = new Symbol(asmLine.data, this, asmLine.dataRange); this.macros.push(s); @@ -81,7 +81,7 @@ export class SymbolFile { } if (instruct.indexOf("bsr") >= 0) { this.subroutines.push(asmLine.data); - } else if ((instruct.indexOf("dc") === 0) || (instruct.indexOf("ds") === 0) || (instruct.indexOf("incbin") === 0)) { + } else if (instruct.startsWith("dc") || instruct.startsWith("ds") || instruct.startsWith("incbin")) { if (lastLabel) { this.dcLabel.push(lastLabel); } @@ -210,13 +210,13 @@ export class Symbol { const line = this.range.start.line; // Current line comment: const currentLine = doc.lineAt(line).text; - const currentLineMatch = currentLine.match(/;\s?(.*)/); + const currentLineMatch = RegExp(/;\s?(.*)/).exec(currentLine); if (currentLineMatch) { commentLines.push(currentLineMatch[1].trim()); } else { // Preceding line comments: for (let i = line - 1; i >= 0; i--) { - const match = doc.lineAt(i).text.match(/^[;*]+-*\s?(.*)/); + const match = RegExp(/^[;*]+-*\s?(.*)/).exec(doc.lineAt(i).text); if (!match) { break; } @@ -224,7 +224,7 @@ export class Symbol { } // Subsequent line comments: for (let i = line + 1; i < doc.lineCount; i++) { - const match = doc.lineAt(i).text.match(/^[;*]+-*\s?(.*)/); + const match = RegExp(/^[;*]+-*\s?(.*)/).exec(doc.lineAt(i).text); if (!match) { break; } diff --git a/src/test/completion.test.ts b/src/test/completion.test.ts index 2cdede8..e35e785 100644 --- a/src/test/completion.test.ts +++ b/src/test/completion.test.ts @@ -4,7 +4,7 @@ // import { expect } from 'chai'; -import { Position, CancellationTokenSource, Uri } from 'vscode'; +import { Position, Uri } from 'vscode'; import { DummyTextDocument } from './dummy'; import * as chaiAsPromised from 'chai-as-promised'; import * as chai from 'chai'; @@ -42,18 +42,16 @@ describe("Completion Tests", function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); const position: Position = new Position(0, 11); - const tokenEmitter = new CancellationTokenSource(); document.addLine(" jsr mymymy"); - const results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + const results = await cp.provideCompletionItems(document, position); expect(results).to.be.empty; }); it("Should return a completion on a library function", async function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); const position: Position = new Position(0, 11); - const tokenEmitter = new CancellationTokenSource(); document.addLine(" jsr oldopen"); - const results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + const results = await cp.provideCompletionItems(document, position); expect(results).to.not.be.undefined; const elm = results[0]; expect(elm.detail).to.be.equal("lib exec.OldOpenLibrary()"); @@ -63,9 +61,8 @@ describe("Completion Tests", function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); const position: Position = new Position(0, 11); - const tokenEmitter = new CancellationTokenSource(); document.addLine(" move.l INTEN"); - const results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + const results = await cp.provideCompletionItems(document, position); expect(results).to.not.be.undefined; const elm = results[0]; expect(elm.detail).to.be.equal("hardware $01C"); @@ -75,9 +72,8 @@ describe("Completion Tests", function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); const position: Position = new Position(0, 11); - const tokenEmitter = new CancellationTokenSource(); document.addLine(" move.l inten"); - const results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + const results = await cp.provideCompletionItems(document, position); expect(results).to.not.be.undefined; const elm = results[0]; expect(elm.label).to.be.equal("intenar"); @@ -86,9 +82,8 @@ describe("Completion Tests", function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); const position: Position = new Position(0, 11); - const tokenEmitter = new CancellationTokenSource(); document.addLine(" move.l d"); - const results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + const results = await cp.provideCompletionItems(document, position); expect(results).to.not.be.undefined; const elm = results.find(e => e.label === "d0")!; expect(elm).to.not.be.empty; @@ -98,9 +93,8 @@ describe("Completion Tests", function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); const position: Position = new Position(0, 11); - const tokenEmitter = new CancellationTokenSource(); document.addLine(" move.l MY_W_V"); - const results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + const results = await cp.provideCompletionItems(document, position); expect(results).to.not.be.undefined; const elm = results[0]; expect(elm.detail).to.be.equal("W/2"); @@ -111,9 +105,8 @@ describe("Completion Tests", function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); const position: Position = new Position(0, 7); - const tokenEmitter = new CancellationTokenSource(); document.addLine(" jsr Mai"); - const results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + const results = await cp.provideCompletionItems(document, position); expect(results).to.not.be.undefined; const elm = results[0]; expect(elm.detail).to.be.equal("label tutorial.s:100"); @@ -123,7 +116,6 @@ describe("Completion Tests", function () { it("Should return a completion on a local label in scope", async function () { const document = new DummyTextDocument(); const position: Position = new Position(1, 8); - const tokenEmitter = new CancellationTokenSource(); document.addLine("Example:"); document.addLine(" jsr .examp"); document.addLine(".example"); @@ -131,7 +123,7 @@ describe("Completion Tests", function () { await definitionHandler.scanFile(document.uri, document); const cp = new M68kCompletionItemProvider(documentationManager, definitionHandler, await state.getLanguage()); - const results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + const results = await cp.provideCompletionItems(document, position); expect(results).to.not.be.empty; const elm = results.find(n => n.label === '.example')!; expect(elm).to.not.be.empty; @@ -141,7 +133,6 @@ describe("Completion Tests", function () { it("Should not return a completion on a local label out of scope", async function () { const document = new DummyTextDocument(); const position: Position = new Position(1, 8); - const tokenEmitter = new CancellationTokenSource(); document.addLine("Example:"); document.addLine(" jsr .examp"); document.addLine("Example2:"); @@ -150,30 +141,28 @@ describe("Completion Tests", function () { await definitionHandler.scanFile(document.uri, document); const cp = new M68kCompletionItemProvider(documentationManager, definitionHandler, await state.getLanguage()); - const results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + const results = await cp.provideCompletionItems(document, position); const elm = results.find(n => n.label === '.example')!; expect(elm).to.be.undefined; }); it("Should not return prefixed local labels", async function () { const document = new DummyTextDocument(); const position: Position = new Position(2, 10); - const tokenEmitter = new CancellationTokenSource(); document.addLine("Example:"); document.addLine(".example"); document.addLine(" jsr Exampl"); const definitionHandler = state.getDefinitionHandler(); await definitionHandler.scanFile(document.uri, document); const cp = new M68kCompletionItemProvider(documentationManager, definitionHandler, await state.getLanguage()); - const results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + const results = await cp.provideCompletionItems(document, position); expect(results).to.have.lengthOf(1); }); it("Should return a completion on an instruction", async function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); const position: Position = new Position(0, 3); - const tokenEmitter = new CancellationTokenSource(); document.addLine(" mov"); - const results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + const results = await cp.provideCompletionItems(document, position); expect(results.length).to.be.equal(7); const elm = results[0]; expect(elm.label).to.be.equal("move"); @@ -184,9 +173,8 @@ describe("Completion Tests", function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); const position: Position = new Position(0, 3); - const tokenEmitter = new CancellationTokenSource(); document.addLine(" MOV"); - const results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + const results = await cp.provideCompletionItems(document, position); expect(results.length).to.be.equal(7); const elm = results[0]; expect(elm.label).to.be.equal("MOVE"); @@ -195,9 +183,8 @@ describe("Completion Tests", function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); const position: Position = new Position(0, 4); - const tokenEmitter = new CancellationTokenSource(); document.addLine(" sect"); - const results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + const results = await cp.provideCompletionItems(document, position); const elm = results[0]; expect(elm.label).to.be.equal("section"); expect(elm.detail).to.be.equal("directive"); @@ -207,9 +194,8 @@ describe("Completion Tests", function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); const position: Position = new Position(0, 4); - const tokenEmitter = new CancellationTokenSource(); document.addLine(" mac"); - const results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + const results = await cp.provideCompletionItems(document, position); const elm = results.find(e => e.label === "macro1")!; expect(elm).to.not.be.undefined; expect(elm.detail).to.be.equal("macro"); @@ -219,11 +205,10 @@ describe("Completion Tests", function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); const position: Position = new Position(1, 10); - const tokenEmitter = new CancellationTokenSource(); document.addLine(" xref MyXref"); document.addLine(" bsr MyXre"); await dHnd.scanFile(document.uri, document); - const results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + const results = await cp.provideCompletionItems(document, position); const elm = results.find(e => e.label === "MyXref")!; expect(elm).to.not.be.undefined; expect(elm.detail).to.be.equal("xref"); @@ -232,24 +217,22 @@ describe("Completion Tests", function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); let position = new Position(0, 6); - const tokenEmitter = new CancellationTokenSource(); document.addLine(" move."); - let results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + let results = await cp.provideCompletionItems(document, position); expect(results.length).to.be.equal(3); const elm = results[0]; expect(elm.label).to.be.equal("b"); position = new Position(1, 6); document.addLine(" move.l"); - results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + results = await cp.provideCompletionItems(document, position); expect(results).to.be.empty; }); it("Should match case of size completions to instruction", async function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); - let position = new Position(0, 6); - const tokenEmitter = new CancellationTokenSource(); + const position = new Position(0, 6); document.addLine(" MOVE."); - let results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + const results = await cp.provideCompletionItems(document, position); const elm = results[0]; expect(elm.label).to.be.equal("B"); }); @@ -257,57 +240,55 @@ describe("Completion Tests", function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); let position = new Position(0, 4); - const tokenEmitter = new CancellationTokenSource(); document.addLine("; mov"); - let results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + let results = await cp.provideCompletionItems(document, position); expect(results).to.be.empty; position = new Position(0, 22); document.addLine(" move.l d0,a1 ; mov"); - results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + results = await cp.provideCompletionItems(document, position); expect(results).to.be.empty; }); it("Should not return completion on a variable or function in an instruction place", async function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); let position = new Position(0, 11); - const tokenEmitter = new CancellationTokenSource(); document.addLine(" OldOpenLib"); - let results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + let results = await cp.provideCompletionItems(document, position); expect(results).to.be.empty; position = new Position(0, 8); document.addLine(" MY_W_VA"); - results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + results = await cp.provideCompletionItems(document, position); expect(results).to.be.empty; }); it("Should not return completion with an instruction in a data", async function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); const position = new Position(0, 11); - const tokenEmitter = new CancellationTokenSource(); document.addLine(" move.l jsr"); - const results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + const results = await cp.provideCompletionItems(document, position); expect(results).to.be.empty; }); it("Should not have the same completion in variable and library function or register", async function () { const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); const document = new DummyTextDocument(); let position = new Position(0, 14); - const tokenEmitter = new CancellationTokenSource(); document.addLine(" jsr AddTail"); - let results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + let results = await cp.provideCompletionItems(document, position); expect(results.length).to.be.equal(1); let elm = results[0]; expect(elm.label).to.be.equal("AddTail"); document.addLine(" move.l INTENAR"); position = new Position(1, 15); - results = await cp.provideCompletionItems(document, position, tokenEmitter.token); + results = await cp.provideCompletionItems(document, position); expect(results.length).to.be.greaterThan(0); elm = results[0]; - expect(elm.label.toString().toUpperCase()).to.be.equal("INTENAR"); + expect(typeof elm.label === 'string'); + if (typeof elm.label === 'string') { + expect(elm.label.toUpperCase()).to.be.equal("INTENAR"); + } }); context("Include completions", function () { const includeSrc = Path.join(PROJECT_ROOT, 'test_files', 'include-dirs', 'example.s'); - const token = (new CancellationTokenSource()).token; let completionProvider: M68kCompletionItemProvider; let defHandler: M68kDefinitionHandler; let doc: DummyTextDocument; @@ -320,7 +301,7 @@ describe("Completion Tests", function () { it("Should return file completions for include", async function () { doc.addLine(" include \"in"); await defHandler.scanFile(doc.uri, doc); - const results = await completionProvider.provideCompletionItems(doc, new Position(0, 14), token); + const results = await completionProvider.provideCompletionItems(doc, new Position(0, 14)); expect(results).to.have.lengthOf(2); expect(results[0].label).to.be.equal("inc-r1.i"); expect(results[1].label).to.be.equal("inc-r2.i"); @@ -328,20 +309,20 @@ describe("Completion Tests", function () { it("Should return file completions filtered by prefix", async function () { doc.addLine(" include \"inc-r2"); await defHandler.scanFile(doc.uri, doc); - const results = await completionProvider.provideCompletionItems(doc, new Position(0, 18), token); + const results = await completionProvider.provideCompletionItems(doc, new Position(0, 18)); expect(results).to.have.lengthOf(1); expect(results[0].label).to.be.equal("inc-r2.i"); }); it("Should return all file completions for include with no input text", async function () { doc.addLine(" include \""); await defHandler.scanFile(doc.uri, doc); - const results = await completionProvider.provideCompletionItems(doc, new Position(0, 14), token); + const results = await completionProvider.provideCompletionItems(doc, new Position(0, 14)); expect(results).to.have.lengthOf(7); }); it("Should return all file completions for directory", async function () { doc.addLine(" include \"b-dir/"); await defHandler.scanFile(doc.uri, doc); - const results = await completionProvider.provideCompletionItems(doc, new Position(0, 19), token); + const results = await completionProvider.provideCompletionItems(doc, new Position(0, 19)); expect(results).to.have.lengthOf(2); expect(results[0].label).to.be.equal("inc-b1.i"); expect(results[1].label).to.be.equal("inc-b2.i"); @@ -349,32 +330,32 @@ describe("Completion Tests", function () { it("Should return directory completions for include", async function () { doc.addLine(" include \"a-"); await defHandler.scanFile(doc.uri, doc); - const results = await completionProvider.provideCompletionItems(doc, new Position(0, 14), token); + const results = await completionProvider.provideCompletionItems(doc, new Position(0, 14)); expect(results).to.have.lengthOf(1); expect(results[0].label).to.be.equal("a-dir/"); }); it("Should return completions for incbin", async function () { doc.addLine(" incbin \"in"); await defHandler.scanFile(doc.uri, doc); - const results = await completionProvider.provideCompletionItems(doc, new Position(0, 14), token); + const results = await completionProvider.provideCompletionItems(doc, new Position(0, 14)); expect(results).to.have.lengthOf(2); }); it("Should return completions for incdir", async function () { doc.addLine(" incdir \"in"); await defHandler.scanFile(doc.uri, doc); - const results = await completionProvider.provideCompletionItems(doc, new Position(0, 14), token); + const results = await completionProvider.provideCompletionItems(doc, new Position(0, 14)); expect(results).to.have.lengthOf(2); }); it("Should return completions with ./ path", async function () { doc.addLine(" include \"./in"); await defHandler.scanFile(doc.uri, doc); - let results = await completionProvider.provideCompletionItems(doc, new Position(0, 16), token); + const results = await completionProvider.provideCompletionItems(doc, new Position(0, 16)); expect(results).to.have.lengthOf(2); }); it("Should return completions with ../ path", async function () { doc.addLine(" include \"../in"); await defHandler.scanFile(doc.uri, doc); - let results = await completionProvider.provideCompletionItems(doc, new Position(0, 17), token); + const results = await completionProvider.provideCompletionItems(doc, new Position(0, 17)); expect(results).to.have.lengthOf(1); expect(results[0].label).to.be.equal("include-dirs/"); }); @@ -382,7 +363,7 @@ describe("Completion Tests", function () { doc.addLine(" incdir \"a-dir\""); doc.addLine(" include \"in"); await defHandler.scanFile(doc.uri, doc); - const results = await completionProvider.provideCompletionItems(doc, new Position(1, 14), token); + const results = await completionProvider.provideCompletionItems(doc, new Position(1, 14)); expect(results).to.have.lengthOf(5); expect(results[0].label).to.be.equal("inc-r1.i"); expect(results[1].label).to.be.equal("inc-r2.i"); @@ -393,20 +374,19 @@ describe("Completion Tests", function () { it("Should return a completion for an include file with an absolute path", async function () { const absPath = Path.join(PROJECT_ROOT, 'test_files', 'debug'); const cp = new M68kCompletionItemProvider(documentationManager, state.getDefinitionHandler(), await state.getLanguage()); - const tokenEmitter = new CancellationTokenSource(); doc.addLine(` include "${absPath}`); - const results = await cp.provideCompletionItems(doc, new Position(0, 12 + absPath.length), tokenEmitter.token); + const results = await cp.provideCompletionItems(doc, new Position(0, 12 + absPath.length)); expect(results.length).to.be.equal(3); expect(results[0].label).to.be.equal("fs-uae/"); expect(results[1].label).to.be.equal("gencop.s"); expect(results[2].label).to.be.equal("hello.c"); }); - it("Should return a completions with mutliple incdir instructions", async function () { + it("Should return a completions with multiple incdir instructions", async function () { doc.addLine(" incdir \"a-dir\""); doc.addLine(" incdir \"b-dir\""); doc.addLine(" include \"in"); await defHandler.scanFile(doc.uri, doc); - const results = await completionProvider.provideCompletionItems(doc, new Position(2, 14), token); + const results = await completionProvider.provideCompletionItems(doc, new Position(2, 14)); expect(results).to.have.lengthOf(7); expect(results[0].label).to.be.equal("inc-r1.i"); expect(results[1].label).to.be.equal("inc-r2.i"); @@ -421,7 +401,7 @@ describe("Completion Tests", function () { await defHandler.scanFile(Uri.file(otherSrc)); doc.addLine(" include \"in"); await defHandler.scanFile(doc.uri, doc); - const results = await completionProvider.provideCompletionItems(doc, new Position(0, 14), token); + const results = await completionProvider.provideCompletionItems(doc, new Position(0, 14)); expect(results).to.have.lengthOf(3); expect(results[0].label).to.be.equal("inc-r1.i"); expect(results[1].label).to.be.equal("inc-r2.i"); @@ -432,7 +412,7 @@ describe("Completion Tests", function () { doc.addLine(" incdir 'b-dir'"); doc.addLine(" include 'in"); await defHandler.scanFile(doc.uri, doc); - const results = await completionProvider.provideCompletionItems(doc, new Position(2, 14), token); + const results = await completionProvider.provideCompletionItems(doc, new Position(2, 14)); expect(results).to.have.lengthOf(7); }); it("Should handle paths without quotes", async function () { @@ -440,14 +420,16 @@ describe("Completion Tests", function () { doc.addLine(" incdir b-dir"); doc.addLine(" include in"); await defHandler.scanFile(doc.uri, doc); - const results = await completionProvider.provideCompletionItems(doc, new Position(2, 13), token); + const results = await completionProvider.provideCompletionItems(doc, new Position(2, 13)); expect(results).to.have.lengthOf(7); }); - it("Should adjust start for path segments contianing word boundaries", async function () { + it("Should adjust start for path segments containing word boundaries", async function () { doc.addLine(" include \"inc-r"); await defHandler.scanFile(doc.uri, doc); - const results = await completionProvider.provideCompletionItems(doc, new Position(0, 16), token); - expect((results[0].range as any).inserting.start.character).to.equal(10); + const results = await completionProvider.provideCompletionItems(doc, new Position(0, 16)); + if (results[0].range && !(results[0].range instanceof vscode.Range)) { + expect(results[0].range.inserting.start.character).to.equal(10); + } }); }); }); diff --git a/src/test/definitionHandler.test.ts b/src/test/definitionHandler.test.ts index 311ac90..df4c37f 100644 --- a/src/test/definitionHandler.test.ts +++ b/src/test/definitionHandler.test.ts @@ -53,7 +53,7 @@ describe("Definition handler Tests", function () { }); context("Editor selection", function () { before(async function () { - let document = await workspace.openTextDocument(Uri.file(MAIN_SOURCE)); + const document = await workspace.openTextDocument(Uri.file(MAIN_SOURCE)); await window.showTextDocument(document); await commands.executeCommand("cursorMove", { to: 'up', by: 'line', value: 20, select: false }); await commands.executeCommand("cursorMove", { to: 'down', by: 'line', value: 20, select: true }); diff --git a/src/test/dummy.ts b/src/test/dummy.ts index 44abb40..8591e33 100644 --- a/src/test/dummy.ts +++ b/src/test/dummy.ts @@ -47,7 +47,6 @@ export class DummyTextDocument implements TextDocument { let s = ""; let startLine = 0; let endLine = this.lineCount; - let startChar = -1; let endChar = -1; if (range) { if (range.start.line === range.end.line) { @@ -56,22 +55,17 @@ export class DummyTextDocument implements TextDocument { } else { startLine = range.start.line; endLine = range.end.line; - startChar = range.start.character; endChar = range.end.character; } } - if (startChar >= 0) { - s += this.lineAt(startLine).text; - } else { - s += this.lineAt(startLine).text; - } + s += this.lineAt(startLine).text; for (let i = startLine + 1; i < endLine - 1; i++) { s += this.lineAt(startLine).text; } if (endChar >= 0) { s += this.lineAt(startLine).text.substring(0, endChar); } else { - s += this.lineAt(startLine); + s += this.lineAt(startLine).text; } return s; } diff --git a/src/test/execHelper.test.ts b/src/test/execHelper.test.ts index 75a0dc9..c8737ec 100644 --- a/src/test/execHelper.test.ts +++ b/src/test/execHelper.test.ts @@ -112,7 +112,7 @@ describe("Executor Tests", function () { warning2.line = 1; warning2.msg = "warn0"; warning2.severity = "warning"; - await ex.handleDiagnosticErrors(document, [error, warning, warning2], undefined); + await ex.handleDiagnosticErrors(document, [error, warning, warning2]); verify(spiedErrorDiagnosticCollection.clear()).never(); verify(spiedWarningDiagnosticCollection.clear()).never(); let [fileUri, newErrors] = capture(spiedErrorDiagnosticCollection.set).last(); @@ -188,7 +188,7 @@ describe("Executor Tests", function () { includedFileError.line = 1; includedFileError.msg = "errorin0"; includedFileError.severity = "error"; - await ex.handleDiagnosticErrors(sourceDocument, [includedFileError], undefined); + await ex.handleDiagnosticErrors(sourceDocument, [includedFileError]); const [fileUri, newErrors] = capture(spiedErrorDiagnosticCollection.set).last(); if (newErrors instanceof Array) { expect(newErrors.length).to.be.equal(1); diff --git a/src/test/expressionDataGenerator.test.ts b/src/test/expressionDataGenerator.test.ts index 6e9159e..da90394 100644 --- a/src/test/expressionDataGenerator.test.ts +++ b/src/test/expressionDataGenerator.test.ts @@ -1,7 +1,7 @@ // The module 'chai' provides assertion methods from node import { expect } from 'chai'; import { ExpressionDataGenerator, ExpressionDataVariable, OutputDataType, ExpressionDataGeneratorSerializer, DataGeneratorCodeLensProvider } from '../expressionDataGenerator'; -import { Uri, Position, window, CancellationTokenSource, commands } from "vscode"; +import { Uri, Position, window, commands } from "vscode"; import { fail } from 'assert'; describe("Expression data generator", function () { @@ -202,13 +202,12 @@ describe("Expression data generator", function () { await commands.executeCommand('workbench.action.closeActiveEditor'); }); it("should locate codelens / resolve and apply", async () => { - const tokenEmitter = new CancellationTokenSource(); const prov = new DataGeneratorCodeLensProvider(); const editor = window.activeTextEditor; // tslint:disable-next-line:no-unused-expression expect(editor).to.not.be.undefined; if (editor) { - const codeLens = await prov.provideCodeLenses(editor.document, tokenEmitter.token); + const codeLens = await prov.provideCodeLenses(editor.document); expect(codeLens.length).to.be.equal(1); const range = codeLens[0].range; expect(range.start).to.be.eql(new Position(0, 0)); @@ -217,7 +216,7 @@ describe("Expression data generator", function () { // resolve const cl = codeLens[0]; if (cl && prov.resolveCodeLens) { - const resolved = await prov.resolveCodeLens(cl, tokenEmitter.token); + const resolved = await prov.resolveCodeLens(cl); // tslint:disable-next-line: no-unused-expression expect(resolved.isResolved).to.be.true; if (resolved.command) { diff --git a/src/test/formatter.test.ts b/src/test/formatter.test.ts index 2186122..c00bdc4 100644 --- a/src/test/formatter.test.ts +++ b/src/test/formatter.test.ts @@ -20,10 +20,7 @@ function getEditsForLine(line: string, enableTabs = false): TextEdit[] { const conf = new DocumentFormatterConfiguration(2, 4, 4, 1, 1, 0, 0, enableTabs, 4); const asmDocument = new ASMDocument(); asmDocument.parse(document, conf); - //asmDocument.maxLabelSize = 9; - //asmDocument.maxInstructionSize = 7; - //asmDocument.maxDataSize = 11; - return f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[0], conf); + return f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[0]); } function getEditsForLineOnType(line: string, enableTabs = false): TextEdit[] { @@ -189,18 +186,18 @@ describe("Formatter Tests", function () { const asmDocument = new ASMDocument(); let conf = new DocumentFormatterConfiguration(1, 1, 4, 1, 1, 0, 0, false, 4); asmDocument.parse(document, conf); - let edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[0], conf); + let edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[0]); let i = 0; expect(edits.length).to.be.equal(3); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(0, 14), new Position(0, 16)), " ")); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(0, 11), new Position(0, 12)), " ")); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(0, 6), new Position(0, 8)), " ")); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[1], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[1]); i = 0; expect(edits.length).to.be.equal(2); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(1, 5), new Position(1, 6)), " ")); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(1, 3), new Position(1, 4)), " ".repeat(6))); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[2], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[2]); i = 0; expect(edits.length).to.be.equal(2); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(2, 13), new Position(2, 14)), " ")); @@ -212,18 +209,18 @@ describe("Formatter Tests", function () { //SC_W\t=\tW conf = new DocumentFormatterConfiguration(1, 1, 4, 1, 1, 0, 0, true, 4); asmDocument.parse(document, conf); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[0], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[0]); i = 0; expect(edits.length).to.be.equal(3); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(0, 14), new Position(0, 16)), "\t")); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(0, 11), new Position(0, 12)), "\t")); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(0, 6), new Position(0, 8)), "\t")); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[1], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[1]); i = 0; expect(edits.length).to.be.equal(2); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(1, 5), new Position(1, 6)), "\t")); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(1, 3), new Position(1, 4)), "\t\t")); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[2], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[2]); i = 0; expect(edits.length).to.be.equal(2); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(2, 13), new Position(2, 14)), "\t")); @@ -250,26 +247,26 @@ describe("Formatter Tests", function () { let asmDocument = new ASMDocument(); let conf = new DocumentFormatterConfiguration(2, 4, 4, 1, 1, 12, 30, false, 4); asmDocument.parse(document, conf); - let edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[0], conf); + let edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[0]); let i = 0; expect(edits.length).to.be.equal(3); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(0, 17), new Position(0, 18)), " ".repeat(5))); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(0, 11), new Position(0, 12)), " ".repeat(4))); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(0, 6), new Position(0, 7)), " ".repeat(6))); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[1], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[1]); expect(edits.length).to.be.equal(0); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[2], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[2]); i = 0; expect(edits.length).to.be.equal(2); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(2, 4), new Position(2, 5)), " ".repeat(15))); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(2, 0), new Position(2, 1)), " ".repeat(12))); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[3], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[3]); expect(edits.length).to.be.equal(0); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[4], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[4]); expect(edits.length).to.be.equal(0); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[5], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[5]); expect(edits.length).to.be.equal(0); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[6], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[6]); i = 0; expect(edits.length).to.be.equal(3); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(6, 5), new Position(6, 6)), " ".repeat(25))); @@ -279,26 +276,26 @@ describe("Formatter Tests", function () { asmDocument = new ASMDocument(); conf = new DocumentFormatterConfiguration(2, 4, 4, 1, 1, 12, 30, true, 4); asmDocument.parse(document, conf); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[0], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[0]); i = 0; expect(edits.length).to.be.equal(3); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(0, 17), new Position(0, 18)), "\t\t")); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(0, 11), new Position(0, 12)), "\t")); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(0, 6), new Position(0, 7)), "\t\t")); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[1], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[1]); expect(edits.length).to.be.equal(0); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[2], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[2]); i = 0; expect(edits.length).to.be.equal(2); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(2, 4), new Position(2, 5)), "\t".repeat(5))); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(2, 0), new Position(2, 1)), "\t".repeat(3))); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[3], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[3]); expect(edits.length).to.be.equal(0); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[4], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[4]); expect(edits.length).to.be.equal(0); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[5], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[5]); expect(edits.length).to.be.equal(0); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[6], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[6]); i = 0; expect(edits.length).to.be.equal(3); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(6, 5), new Position(6, 6)), "\t".repeat(6))); @@ -322,14 +319,14 @@ describe("Formatter Tests", function () { const asmDocument = new ASMDocument(); const conf = new DocumentFormatterConfiguration(2, 4, 4, 1, 1, 0, 0, false, 4); asmDocument.parse(document, conf); - let edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[0], conf); + let edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[0]); let i = 0; expect(edits.length).to.be.equal(2); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(0, 13), new Position(0, 22)), " ".repeat(9))); expect(edits[i]).to.be.eql(TextEdit.replace(new Range(new Position(0, 0), new Position(0, 8)), " ".repeat(2))); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[1], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[1]); expect(edits.length).to.be.equal(1); - edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[4], conf); + edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[4]); i = 0; expect(edits.length).to.be.equal(2); expect(edits[i++]).to.be.eql(TextEdit.replace(new Range(new Position(4, 18), new Position(4, 22)), " ".repeat(4))); @@ -342,7 +339,7 @@ describe("Formatter Tests", function () { const asmDocument = new ASMDocument(); const conf = new DocumentFormatterConfiguration(2, 4, 4, 1, 1, 0, 0, false, 4); asmDocument.parse(document, conf); - let edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[0], conf); + const edits = f.computeEditsForLine(asmDocument, asmDocument.asmLinesArray[0]); expect(edits.length).to.be.equal(0); }); }); diff --git a/src/test/fsProxy.test.ts b/src/test/fsProxy.test.ts index 0c1e8b9..18f946d 100644 --- a/src/test/fsProxy.test.ts +++ b/src/test/fsProxy.test.ts @@ -268,7 +268,7 @@ describe("FsProxy test", function () { const writtenContents = "my new test is good test"; const buf = Buffer.from(writtenContents); await f.writeFile(buf); - await f.replaceStringInFile(new RegExp("test", "g"), "done"); + await f.replaceStringInFile(/test/g, "done"); const contents = await f.readFile(); expect(contents.toString()).to.be.eq("my new done is good done") }); diff --git a/src/vasm.ts b/src/vasm.ts index 3fc7f04..7bde26e 100755 --- a/src/vasm.ts +++ b/src/vasm.ts @@ -63,7 +63,7 @@ export class VASMCompiler { public async buildCurrentEditorFile(vasmConf?: VasmBuildProperties, logEmitter?: EventEmitter): Promise { const editor = window.activeTextEditor; if (editor) { - const conf = this.getConfiguration("vasm", vasmConf); + const conf: VasmBuildProperties = this.getConfiguration("vasm", vasmConf) as VasmBuildProperties; if (this.mayCompile(conf)) { await this.buildDocument({ ...conf }, editor.document, true, logEmitter); } else { @@ -110,7 +110,7 @@ export class VASMCompiler { ); for (let k = 0; k < document.lineCount; k += 1) { const line = document.lineAt(k).text; - if (line.match(regexp)) { + if (RegExp(regexp).exec(line)) { error.line = k + 1; break; } @@ -123,7 +123,7 @@ export class VASMCompiler { } } - private getConfiguration(key: string, properties?: any): any { + private getConfiguration(key: string, properties?: unknown): unknown { if (properties) { return properties; } else if (key === "vasm") { @@ -140,9 +140,9 @@ export class VASMCompiler { const errorDiagnosticCollection = state.getErrorDiagnosticCollection(); errorDiagnosticCollection.clear(); warningDiagnosticCollection.clear(); - const conf: any = this.getConfiguration("vasm", vasmBuildProperties); + const conf: VasmBuildProperties = this.getConfiguration("vasm", vasmBuildProperties) as VasmBuildProperties; if (this.mayCompile(conf)) { - const confVLINK: any = this.getConfiguration("vlink", vlinkBuildProperties); + const confVLINK: VlinkBuildProperties = this.getConfiguration("vlink", vlinkBuildProperties) as VlinkBuildProperties; if (confVLINK) { await this.buildWorkspaceInner(conf, confVLINK, logEmitter); } else { @@ -410,7 +410,7 @@ export class VASMCompiler { if (logEmitter) { logEmitter.fire(`building ${objFilename}\r\n`); } - const results = await this.executor.runTool(args, workspaceRootDir.fsPath, "warning", true, vasmExecutableName, null, true, this.parser, undefined, logEmitter); + const results = await this.executor.runTool(args, workspaceRootDir.fsPath, "warning", true, vasmExecutableName, undefined, true, this.parser, undefined, logEmitter); return [objFilename, results]; } else if (!this.disabledInConf(conf)) { throw VASMCompiler.CONFIGURE_VASM_ERROR; @@ -428,7 +428,7 @@ export class VASMCompiler { * @param conf Configuration */ mayCompile(conf: VasmBuildProperties): boolean { - return conf && conf.enabled; + return conf?.enabled; } /** diff --git a/src/vlink.ts b/src/vlink.ts index dfd7168..a8a5022 100644 --- a/src/vlink.ts +++ b/src/vlink.ts @@ -93,15 +93,15 @@ export class VLINKLinker { } } const args: Array = confArgs.concat(['-o', path.join(buildDir.fsPath, exeFilepathname)]).concat(objectPathNames); - return this.executor.runTool(args, workspaceRootDir.fsPath, "warning", true, vlinkExecutableName, null, true, this.parser, undefined, logEmitter); + return this.executor.runTool(args, workspaceRootDir.fsPath, "warning", true, vlinkExecutableName, undefined, true, this.parser, undefined, logEmitter); } /** * Function to check if it is possible to link * @param conf Configuration */ - mayLink(conf: any): boolean { - return (conf && conf.enabled); + mayLink(conf: VlinkBuildProperties): boolean { + return (conf?.enabled); } } @@ -113,8 +113,8 @@ export class VLINKParser implements ExecutorParser { parse(text: string): ICheckResult[] { const errors: ICheckResult[] = []; const lines = text.split(/\r\n|\r|\n/g); - for (let lineIndex = 0; lineIndex < lines.length; lineIndex += 1) { - const line = lines[lineIndex]; + for (const element of lines) { + const line = element; if ((line.length > 1) && !line.startsWith('>')) { let match = /(error|warning|message)\s([\d]+)\sin\sline\s([\d]+)\sof\s["](.+)["]:\s*(.*)/i.exec(line); if (match) {