From d71e5058bd92aef1725535048e1d46c1ae4735c3 Mon Sep 17 00:00:00 2001 From: xqzlgy2 Date: Fri, 27 Nov 2020 10:14:04 +0800 Subject: [PATCH] Modify tsconfig & error fix --- package-lock.json | 16 +++++++++++++ package.json | 1 + src/build.ts | 2 +- src/commands.ts | 4 ++-- src/configurationProvider.ts | 29 ++++++++++++------------ src/extension.ts | 6 ++--- src/hotCodeReplace.ts | 3 ++- src/hoverProvider.ts | 6 +++-- src/javaDebugAdapterDescriptorFactory.ts | 5 ++-- src/javaLogger.ts | 2 +- src/languageServerPlugin.ts | 4 ++-- src/launchCommand.ts | 4 ++-- src/mainClassPicker.ts | 6 +++-- src/processPicker.ts | 8 +++++-- src/terminalLinkProvider.ts | 4 +++- src/utility.ts | 4 ++-- test/extension.test.ts | 2 +- tsconfig.json | 9 ++++++-- 18 files changed, 75 insertions(+), 40 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0b8d6a97..e335d0fb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,12 +30,28 @@ "integrity": "sha512-mQjDxyOM1Cpocd+vm1kZBP7smwKZ4TNokFeds9LV7OZibmPJFEzY3+xZMrKfUdNT71lv8GoCPD6upKwHxubClw==", "dev": true }, + "@types/glob": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.3.tgz", + "integrity": "sha512-SEYeGAIQIQX8NN6LDKprLjbrd5dARM5EXsd8GI/A5l0apYI1fGMWgPHSe4ZKL4eozlAyI+doUE9XbYS4xCkQ1w==", + "dev": true, + "requires": { + "@types/minimatch": "*", + "@types/node": "*" + } + }, "@types/lodash": { "version": "4.14.137", "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.137.tgz", "integrity": "sha512-g4rNK5SRKloO+sUGbuO7aPtwbwzMgjK+bm9BBhLD7jGUiGR7zhwYEhSln/ihgYQBeIJ5j7xjyaYzrWTcu3UotQ==", "dev": true }, + "@types/minimatch": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz", + "integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==", + "dev": true + }, "@types/mocha": { "version": "5.2.7", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-5.2.7.tgz", diff --git a/package.json b/package.json index 0610a734..492cee36 100644 --- a/package.json +++ b/package.json @@ -753,6 +753,7 @@ "test": "npm run compile && node ./out/test/index.js" }, "devDependencies": { + "@types/glob": "^7.1.3", "@types/lodash": "^4.14.137", "@types/mocha": "^5.2.7", "@types/node": "^8.10.51", diff --git a/src/build.ts b/src/build.ts index 8c2a4a80..93560e9f 100644 --- a/src/build.ts +++ b/src/build.ts @@ -86,7 +86,7 @@ function checkErrorsReportedByJavaExtension(): boolean { } async function showFixSuggestions(operationId: string) { - let buildFiles = []; + let buildFiles: string[] = []; try { buildFiles = await lsPlugin.resolveBuildFiles(); } catch (error) { diff --git a/src/commands.ts b/src/commands.ts index f8dbeda4..9aa3dfd1 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -44,11 +44,11 @@ export const JAVA_RESOLVE_CLASSFILTERS = "vscode.java.resolveClassFilters"; export const JAVA_RESOLVE_SOURCE_URI = "vscode.java.resolveSourceUri"; -export function executeJavaLanguageServerCommand(...rest) { +export function executeJavaLanguageServerCommand(...rest: any[]) { return executeJavaExtensionCommand(JAVA_EXECUTE_WORKSPACE_COMMAND, ...rest); } -export async function executeJavaExtensionCommand(commandName: string, ...rest) { +export async function executeJavaExtensionCommand(commandName: string, ...rest: any[]) { // TODO: need to handle error and trace telemetry const javaExtension = utility.getJavaExtension(); if (!javaExtension) { diff --git a/src/configurationProvider.ts b/src/configurationProvider.ts index cd3a3d82..69b9f0f1 100644 --- a/src/configurationProvider.ts +++ b/src/configurationProvider.ts @@ -4,7 +4,6 @@ import * as fs from "fs"; import * as _ from "lodash"; import * as os from "os"; import * as path from "path"; -import { debug } from "util"; import * as vscode from "vscode"; import { instrumentOperation, sendInfo } from "vscode-extension-telemetry-wrapper"; @@ -19,7 +18,7 @@ import { mainClassPicker } from "./mainClassPicker"; import { resolveJavaProcess } from "./processPicker"; import * as utility from "./utility"; -const platformNameMappings = { +const platformNameMappings: {[key: string]: string} = { win32: "windows", linux: "linux", darwin: "osx", @@ -38,20 +37,22 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration this.isUserSettingsDirty = true; } } + return undefined; }); } // Returns an initial debug configurations based on contextual information. - public provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken): + public provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, _token?: vscode.CancellationToken): vscode.ProviderResult { - const provideDebugConfigurationsHandler = instrumentOperation("provideDebugConfigurations", (operationId: string) => { + const provideDebugConfigurationsHandler = instrumentOperation("provideDebugConfigurations", (_operationId: string) => { return >this.provideDebugConfigurationsAsync(folder); }); return provideDebugConfigurationsHandler(); } // Try to add all missing attributes to the debug configuration being launched. - public resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, token?: vscode.CancellationToken): + public resolveDebugConfiguration(_folder: vscode.WorkspaceFolder | undefined, + config: vscode.DebugConfiguration, _token?: vscode.CancellationToken): vscode.ProviderResult { // If no debug configuration is provided, then generate one in memory. if (this.isEmptyConfig(config)) { @@ -67,8 +68,8 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration public resolveDebugConfigurationWithSubstitutedVariables( folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, - token?: vscode.CancellationToken): vscode.ProviderResult { - const resolveDebugConfigurationHandler = instrumentOperation("resolveDebugConfiguration", (operationId: string) => { + _token?: vscode.CancellationToken): vscode.ProviderResult { + const resolveDebugConfigurationHandler = instrumentOperation("resolveDebugConfiguration", (_operationId: string) => { try { // See https://github.com/microsoft/vscode-java-debug/issues/778 // Merge the platform specific properties to the global config to simplify the subsequent resolving logic. @@ -85,9 +86,9 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration return resolveDebugConfigurationHandler(); } - private provideDebugConfigurationsAsync(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken) { + private provideDebugConfigurationsAsync(folder: vscode.WorkspaceFolder | undefined, _token?: vscode.CancellationToken) { return vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, (p) => { - return new Promise(async (resolve, reject) => { + return new Promise(async (resolve, _reject) => { p.report({ message: "Auto generating configuration..." }); const defaultLaunchConfig = { type: "java", @@ -104,7 +105,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration } const mainClasses = await lsPlugin.resolveMainClass(folder ? folder.uri : undefined); - let cache; + let cache: {[key: string]: any}; cache = {}; const launchConfigs = mainClasses.map((item) => { return { @@ -126,7 +127,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration }); } - private mergePlatformProperties(folder: vscode.WorkspaceFolder, config: vscode.DebugConfiguration) { + private mergePlatformProperties(_folder: vscode.WorkspaceFolder, config: vscode.DebugConfiguration) { if (config && platformName && config[platformName]) { try { for (const key of Object.keys(config[platformName])) { @@ -139,7 +140,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration } } - private constructLaunchConfigName(mainClass: string, projectName: string, cache: {}) { + private constructLaunchConfigName(mainClass: string, projectName: string, cache: {[key: string]: any}) { const prefix = "Debug (Launch)-"; let name = prefix + mainClass.substr(mainClass.lastIndexOf(".") + 1); if (projectName !== undefined) { @@ -199,7 +200,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration const mainClassOption = await this.resolveLaunchConfig(folder ? folder.uri : undefined, config); if (!mainClassOption || !mainClassOption.mainClass) { // Exit silently if the user cancels the prompt fix by ESC. // Exit the debug session. - return; + return undefined; } config.mainClass = mainClassOption.mainClass; @@ -406,7 +407,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration return selectedFix; } // return undefined if the user clicks "Learn More". - return; + return undefined; } throw new utility.UserError({ diff --git a/src/extension.ts b/src/extension.ts index a4f8c3ed..de522f2f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -14,7 +14,7 @@ import { initializeCodeLensProvider, startDebugging } from "./debugCodeLensProvi import { handleHotCodeReplaceCustomEvent, initializeHotCodeReplace, NO_BUTTON, YES_BUTTON } from "./hotCodeReplace"; import { JavaDebugAdapterDescriptorFactory } from "./javaDebugAdapterDescriptorFactory"; import { logJavaException, logJavaInfo } from "./javaLogger"; -import { IMainClassOption, IMainMethod, resolveMainClass, resolveMainMethod } from "./languageServerPlugin"; +import { IMainClassOption, IMainMethod, resolveMainMethod } from "./languageServerPlugin"; import { logger, Type } from "./logger"; import { mainClassPicker } from "./mainClassPicker"; import { pickJavaProcess } from "./processPicker"; @@ -29,7 +29,7 @@ export async function activate(context: vscode.ExtensionContext) { await instrumentOperation("activation", initializeExtension)(context); } -function initializeExtension(operationId: string, context: vscode.ExtensionContext) { +function initializeExtension(_operationId: string, context: vscode.ExtensionContext) { // Deprecated logger.initialize(context, true); @@ -123,7 +123,7 @@ function registerDebugEventListener(context: vscode.ExtensionContext) { })); } -function handleUserNotification(customEvent) { +function handleUserNotification(customEvent: vscode.DebugSessionCustomEvent) { if (customEvent.body.notificationType === "ERROR") { utility.showErrorMessageWithTroubleshooting({ message: customEvent.body.message, diff --git a/src/hotCodeReplace.ts b/src/hotCodeReplace.ts index 6a6acc92..e14408d7 100644 --- a/src/hotCodeReplace.ts +++ b/src/hotCodeReplace.ts @@ -38,7 +38,7 @@ export function initializeHotCodeReplace(context: vscode.ExtensionContext) { })); } -export function handleHotCodeReplaceCustomEvent(hcrEvent) { +export function handleHotCodeReplaceCustomEvent(hcrEvent: vscode.DebugSessionCustomEvent) { if (hcrEvent.body.changeType === HcrChangeType.BUILD_COMPLETE) { if (getHotReloadFlag() === "auto") { return vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, (progress) => { @@ -62,6 +62,7 @@ export function handleHotCodeReplaceCustomEvent(hcrEvent) { }); } } + return undefined; } function getHotReloadFlag(): string { diff --git a/src/hoverProvider.ts b/src/hoverProvider.ts index b72ca881..2a44ffa9 100644 --- a/src/hoverProvider.ts +++ b/src/hoverProvider.ts @@ -43,10 +43,10 @@ class DebugHoverProvider implements Disposable { } class InternalDebugHoverProvider implements HoverProvider { - public provideHover(document: TextDocument, position: Position, token: CancellationToken): ProviderResult { + public provideHover(document: TextDocument, position: Position, _token: CancellationToken): ProviderResult { const range = document.getWordRangeAtPosition(position, /\w+/); if (!range || document.getText(range) !== "main") { - return; + return undefined; } const line = document.lineAt(position); @@ -69,6 +69,8 @@ class InternalDebugHoverProvider implements HoverProvider { contributed.isTrusted = true; return new Hover(contributed); } + + return undefined; } private isMainMethod(line: string): boolean { diff --git a/src/javaDebugAdapterDescriptorFactory.ts b/src/javaDebugAdapterDescriptorFactory.ts index 8939d8b3..b82e77b3 100644 --- a/src/javaDebugAdapterDescriptorFactory.ts +++ b/src/javaDebugAdapterDescriptorFactory.ts @@ -8,8 +8,8 @@ import { Type } from "./logger"; import { convertErrorToMessage, showErrorMessageWithTroubleshooting } from "./utility"; export class JavaDebugAdapterDescriptorFactory implements DebugAdapterDescriptorFactory { - public async createDebugAdapterDescriptor(session: DebugSession, executable: DebugAdapterExecutable): Promise { - let error; + public async createDebugAdapterDescriptor(_session: DebugSession, _executable: DebugAdapterExecutable): Promise { + let error: Error; try { const debugServerPort = (await startDebugSession()); if (debugServerPort) { @@ -28,5 +28,6 @@ export class JavaDebugAdapterDescriptorFactory implements DebugAdapterDescriptor message: "Failed to start debug server.", }; showErrorMessageWithTroubleshooting(message); + return undefined; } } diff --git a/src/javaLogger.ts b/src/javaLogger.ts index bcafac9e..7158d43a 100644 --- a/src/javaLogger.ts +++ b/src/javaLogger.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -import { sendError, sendInfo, sendOperationError } from "vscode-extension-telemetry-wrapper"; +import { sendInfo, sendOperationError } from "vscode-extension-telemetry-wrapper"; export function logJavaException(errorProperties: any): void { /** diff --git a/src/languageServerPlugin.ts b/src/languageServerPlugin.ts index 65ce4520..8bedfe5b 100644 --- a/src/languageServerPlugin.ts +++ b/src/languageServerPlugin.ts @@ -45,7 +45,7 @@ export function startDebugSession() { return commands.executeJavaLanguageServerCommand(commands.JAVA_START_DEBUGSESSION); } -export function resolveClasspath(mainClass, projectName) { +export function resolveClasspath(mainClass: string, projectName: string) { return commands.executeJavaLanguageServerCommand(commands.JAVA_RESOLVE_CLASSPATH, mainClass, projectName); } @@ -101,7 +101,7 @@ export async function isOnClasspath(uri: string): Promise { } } -export function resolveJavaExecutable(mainClass, projectName) { +export function resolveJavaExecutable(mainClass: string, projectName: string) { return commands.executeJavaLanguageServerCommand(commands.JAVA_RESOLVE_JAVAEXECUTABLE, mainClass, projectName); } diff --git a/src/launchCommand.ts b/src/launchCommand.ts index 9ceaca6d..00ccf2c8 100644 --- a/src/launchCommand.ts +++ b/src/launchCommand.ts @@ -60,8 +60,8 @@ export async function addMoreHelpfulVMArgs(config: vscode.DebugConfiguration) { } function checkJavaVersion(javaExec: string): Promise { - return new Promise((resolve, reject) => { - cp.execFile(javaExec, ["-version"], {}, (error, stdout, stderr) => { + return new Promise((resolve, _reject) => { + cp.execFile(javaExec, ["-version"], {}, (_error, _stdout, stderr) => { const javaVersion = parseMajorVersion(stderr); resolve(javaVersion); }); diff --git a/src/mainClassPicker.ts b/src/mainClassPicker.ts index afb59216..4d66c5de 100644 --- a/src/mainClassPicker.ts +++ b/src/mainClassPicker.ts @@ -35,7 +35,7 @@ class MainClassPicker { } if (!options || !options.length) { - return; + return undefined; } else if (autoPick && options.length === 1) { return options[0]; } @@ -53,6 +53,7 @@ class MainClassPicker { if (selected) { return selected.data; } + return undefined; } // tslint:disable-next-line @@ -77,7 +78,7 @@ class MainClassPicker { } if (!options || !options.length) { - return; + return undefined; } else if (autoPick && options.length === 1) { return options[0]; } @@ -146,6 +147,7 @@ class MainClassPicker { this.updateMRUTimestamp(selected.data); return selected.data; } + return undefined; } private getMRUTimestamp(mainClassOption: IMainClassOption): number { diff --git a/src/processPicker.ts b/src/processPicker.ts index b496e0de..8dc5a2bd 100644 --- a/src/processPicker.ts +++ b/src/processPicker.ts @@ -2,7 +2,7 @@ // Licensed under the MIT license. import * as path from "path"; -import { DebugConfiguration, window } from "vscode"; +import { window } from "vscode"; import { getProcesses, getProcessTree } from "./processTree"; const JAVA_PATTERN = /(?:java|javaw|j9|j9w)$/i; @@ -42,12 +42,14 @@ function convertToJavaProcess(pid: number, command: string, args: string): IJava }; } } + + return undefined; } export async function pickJavaProcess(): Promise { const javaProcesses: IJavaProcess[] = []; try { - await getProcesses((pid: number, ppid: number, command: string, args: string, date: number) => { + await getProcesses((pid: number, _ppid: number, command: string, args: string, _date: number) => { const javaProcess = convertToJavaProcess(pid, command, args); if (javaProcess) { javaProcesses.push(javaProcess); @@ -79,6 +81,8 @@ export async function pickJavaProcess(): Promise { if (pick) { return pick.process; } + + return undefined; } export async function resolveJavaProcess(pid: number): Promise { diff --git a/src/terminalLinkProvider.ts b/src/terminalLinkProvider.ts index 3aae20b0..6d5db9d1 100644 --- a/src/terminalLinkProvider.ts +++ b/src/terminalLinkProvider.ts @@ -14,7 +14,7 @@ export class JavaTerminalLinkProvder implements TerminalLinkProvider { + public provideTerminalLinks(context: TerminalLinkContext, _token: CancellationToken): ProviderResult { if (context.terminal.name !== "Java Debug Console" && context.terminal.name !== "Java Process Console") { return []; } @@ -32,6 +32,8 @@ export class JavaTerminalLinkProvder implements TerminalLinkProvider { test("should activate", function() { this.timeout(1 * 60 * 1000); - return vscode.extensions.getExtension("vscjava.vscode-java-debug").activate().then((api) => { + return vscode.extensions.getExtension("vscjava.vscode-java-debug").activate().then((_api) => { assert.ok(true); }); }); diff --git a/tsconfig.json b/tsconfig.json index a63aeea4..1f32c464 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,12 +3,17 @@ "module": "commonjs", "target": "es6", "outDir": "out", - "alwaysStrict": true, "lib": [ "es6" ], "sourceMap": true, - "rootDir": "." + "rootDir": ".", + "noUnusedLocals": true, + "noImplicitThis": true, + "noImplicitAny": true, + "noImplicitReturns": true, + "noUnusedParameters": true, + "alwaysStrict": true }, "exclude": [ "node_modules",