Skip to content

Commit dc0fed7

Browse files
committed
Resolve new linting issues
Signed-off-by: David Thompson <[email protected]>
1 parent 0fb5c0d commit dc0fed7

11 files changed

+76
-52
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
"test-compile": "tsc -p ./",
256256
"pretest": "npm run test-compile",
257257
"test": "node ./out/test/runTest.js",
258-
"eslint": "npx eslint --fix src/**/*.ts",
258+
"eslint": "npx eslint --fix src",
259259
"build": "npx gulp build",
260260
"build-server": "npx gulp buildServer",
261261
"build-ext": "npx gulp buildExtension"

src/definitions/vscodeJavaApi.ts

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright 2024 Red Hat, Inc. and others.
3+
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import type { Event } from "vscode";
17+
18+
/**
19+
* @see https://github.com/redhat-developer/vscode-java/blob/master/src/extension.api.ts#L116
20+
*/
21+
export type JavaExtensionAPI = {
22+
serverMode: ServerMode;
23+
readonly javaRequirement: RequirementsData;
24+
readonly onDidServerModeChange: Event<ServerMode>;
25+
readonly serverReady: () => Promise<boolean>;
26+
};
27+
28+
export enum ServerMode {
29+
STANDARD = "Standard",
30+
LIGHTWEIGHT = "LightWeight",
31+
HYBRID = "Hybrid",
32+
}
33+
34+
/* eslint-disable @typescript-eslint/naming-convention */
35+
export interface RequirementsData {
36+
tooling_jre: string;
37+
tooling_jre_version: number;
38+
java_home: string;
39+
java_version: number;
40+
}

src/extension.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,26 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { getRedHatService, TelemetryService } from '@redhat-developer/vscode-redhat-telemetry/lib';
1716
import { RedHatService } from '@redhat-developer/vscode-redhat-telemetry';
18-
import { CodeAction as VSCodeAction, CodeActionKind, Command as VSCommand, commands, Diagnostic as VSDiagnostic, ExtensionContext, extensions, window, workspace, TextDocument, FileCreateEvent } from 'vscode';
17+
import { getRedHatService, TelemetryService } from '@redhat-developer/vscode-redhat-telemetry/lib';
18+
import { CodeActionKind, commands, ExtensionContext, extensions, FileCreateEvent, TextDocument, CodeAction as VSCodeAction, Command as VSCommand, Diagnostic as VSDiagnostic, window, workspace } from 'vscode';
1919
import { CancellationToken, CodeAction, CodeActionResolveRequest, Command, DidChangeConfigurationNotification, DocumentSelector, LanguageClientOptions, RequestType } from 'vscode-languageclient';
2020
import { LanguageClient } from 'vscode-languageclient/node';
2121
import { APPLY_CODE_ACTION_WITH_TELEMETRY } from './definitions/commands';
2222
import * as CommandKind from './definitions/lspCommandKind';
2323
import * as MicroProfileLS from './definitions/microProfileLSRequestNames';
24+
import { JavaExtensionAPI } from './definitions/vscodeJavaApi';
2425
import { prepareExecutable } from './languageServer/javaServerStarter';
2526
import { collectMicroProfileJavaExtensions, handleExtensionChange, MicroProfileContribution } from './languageServer/plugin';
2627
import { resolveRequirements } from './languageServer/requirements';
2728
import { registerConfigurationUpdateCommand, registerOpenURICommand } from './lsp-commands';
2829
import { JAVA_EXTENSION_ID, waitForStandardMode } from './util/javaServerMode';
2930
import { sendCodeActionTelemetry } from './util/telemetry';
3031
import { getFilePathsFromWorkspace } from './util/workspaceUtils';
31-
import { MicroProfilePropertiesChangeEvent, registerYamlSchemaSupport, YamlSchemaCache, getYamlSchemaCache } from './yaml/YamlSchema';
32+
import { getYamlSchemaCache, MicroProfilePropertiesChangeEvent, registerYamlSchemaSupport, YamlSchemaCache } from './yaml/YamlSchema';
3233

3334
let languageClient: LanguageClient;
3435

35-
// alias for vscode-java's ExtensionAPI
36-
export type JavaExtensionAPI = any;
37-
3836
export async function activate(context: ExtensionContext): Promise<void> {
3937
if (await isJavaProject()) {
4038
await doActivate(context);
@@ -296,7 +294,7 @@ async function connectToLS(context: ExtensionContext, api: JavaExtensionAPI, doc
296294
* Returns a json object with key 'microprofile' and a json object value that
297295
* holds all microprofile settings.
298296
*/
299-
function getVSCodeMicroProfileSettings(): { microprofile: any } {
297+
function getVSCodeMicroProfileSettings(): { microprofile } {
300298
const defaultMicroProfileSettings = {};
301299
const configMicroProfile = workspace.getConfiguration().get('microprofile');
302300
const microprofileSettings = configMicroProfile ? configMicroProfile : defaultMicroProfileSettings;

src/languageServer/javaServerStarter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as os from 'os';
33
import * as path from 'path';
44
import { workspace } from 'vscode';
55
import { Executable, ExecutableOptions } from 'vscode-languageclient/node';
6-
import { RequirementsData } from './requirements';
6+
import { RequirementsData } from '../definitions/vscodeJavaApi';
77

88
const DEBUG = startedInDebugMode();
99
const DEBUG_PORT = 1064;

src/languageServer/plugin.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as vscode from 'vscode';
21
import * as path from 'path';
3-
import * as Commands from '../definitions/commands';
4-
import { DocumentFilter, DocumentSelector } from 'vscode-languageclient';
52
import { isDeepStrictEqual } from 'util';
3+
import * as vscode from 'vscode';
4+
import { DocumentFilter, DocumentSelector, TextDocumentFilter } from 'vscode-languageclient';
5+
import * as Commands from '../definitions/commands';
66

77
let existingExtensions: MicroProfileContribution[];
88

@@ -19,7 +19,7 @@ export interface MicroProfileContribution {
1919
*
2020
* @param extensions array of extensions to search contributions from
2121
*/
22-
export function collectMicroProfileJavaExtensions(extensions: readonly vscode.Extension<any>[]): MicroProfileContribution[] {
22+
export function collectMicroProfileJavaExtensions(extensions: readonly vscode.Extension<unknown>[]): MicroProfileContribution[] {
2323
const result: MicroProfileContribution[] = [];
2424
if (extensions && extensions.length) {
2525
for (const extension of extensions) {
@@ -42,7 +42,7 @@ export function collectMicroProfileJavaExtensions(extensions: readonly vscode.Ex
4242
return result;
4343
}
4444

45-
export function handleExtensionChange(extensions: readonly vscode.Extension<any>[]): void {
45+
export function handleExtensionChange(extensions: readonly vscode.Extension<unknown>[]): void {
4646
if (!existingExtensions) {
4747
return;
4848
}
@@ -78,20 +78,20 @@ export function handleExtensionChange(extensions: readonly vscode.Extension<any>
7878
}
7979
}
8080

81-
function setJarExtensionsIfExists(obj: MicroProfileContribution, section: any, extensionPath: string): void {
81+
function setJarExtensionsIfExists(obj: MicroProfileContribution, section: { jarExtensions: string[]; }, extensionPath: string): void {
8282
if (Array.isArray(section.jarExtensions)) {
8383
for (const microprofileJavaExtensionPath of section.jarExtensions) {
8484
obj.jarExtensions.push(path.resolve(extensionPath, microprofileJavaExtensionPath));
8585
}
8686
}
8787
}
8888

89-
function setDocumentSelectorIfExists(obj: MicroProfileContribution, section: any): void {
90-
if (!Array.isArray(section.documentSelector)) {
89+
function setDocumentSelectorIfExists(obj: MicroProfileContribution, section: { documentSelector: (string | TextDocumentFilter)[]; }): void {
90+
if (!section.documentSelector || !Array.isArray(section.documentSelector)) {
9191
return;
9292
}
9393
const documentSelector: DocumentSelector = [];
94-
section.documentSelector.forEach((selector: any) => {
94+
section.documentSelector.forEach((selector) => {
9595
if (typeof selector === 'string') {
9696
documentSelector.push(selector);
9797
} else if (selector) {

src/languageServer/requirements.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,11 @@ import * as path from 'path';
66
import { Uri, workspace } from 'vscode';
77

88
import * as expandHomeDir from 'expand-home-dir';
9-
import { findRuntimes, IJavaRuntime, getSources } from 'jdk-utils';
10-
import { JavaExtensionAPI } from '../extension';
9+
import { IJavaRuntime, findRuntimes, getSources } from 'jdk-utils';
10+
import { JavaExtensionAPI, RequirementsData } from '../definitions/vscodeJavaApi';
1111
const isWindows = process.platform.indexOf('win') === 0;
1212
const JAVA_FILENAME = 'java' + (isWindows ? '.exe' : '');
1313

14-
export interface RequirementsData {
15-
tooling_jre: string;
16-
tooling_jre_version: number;
17-
java_home: string;
18-
java_version: number;
19-
}
20-
2114
/**
2215
* Resolves the requirements needed to run the extension.
2316
* Returns a promise that will resolve to a RequirementsData if

src/lsp-commands.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function addToPreferenceArray<T>(key: string, value: T): void {
7777

7878
interface ConfigurationItemEdit {
7979
section: string;
80-
value: any;
80+
value;
8181
editType: ConfigurationItemEditType;
8282
}
8383

src/test/suite/languageServer/documentSelectorPlugin.test.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
import { expect } from "chai";
1617
import * as vscode from "vscode";
18+
import { DocumentSelector, TextDocumentFilter } from "vscode-languageclient";
1719
import * as plugin from "../../../languageServer/plugin";
18-
import { expect } from "chai";
1920
import { MicroProfileContribution } from "../../../languageServer/plugin";
20-
import { TextDocumentFilter, DocumentSelector } from "vscode-languageclient";
2121

2222
/**
2323
* This file ensures that DocumentSelectors contributed by other VS Code extensions
@@ -167,8 +167,8 @@ describe("Document selector collection from language server plugins", () => {
167167
*
168168
* @param pluginDocumentSelector array of objects to create a DocumentSelector from.
169169
*/
170-
function collectDocumentSelectors(pluginDocumentSelector: any[]): DocumentSelector {
171-
const fakePlugin: vscode.Extension<any> = {
170+
function collectDocumentSelectors(pluginDocumentSelector: unknown[]): DocumentSelector {
171+
const fakePlugin: vscode.Extension<unknown> = {
172172
id: "fake-no-plugin-extension",
173173
extensionUri: vscode.Uri.parse("https://example.org"),
174174
extensionPath: "",
@@ -188,7 +188,6 @@ describe("Document selector collection from language server plugins", () => {
188188
const contribution: MicroProfileContribution[] = plugin.collectMicroProfileJavaExtensions([ fakePlugin ]);
189189
expect(contribution).to.have.length(1);
190190

191-
const selector: DocumentSelector = contribution[0].documentSelector;
192191
return contribution[0].documentSelector;
193192
}
194193
});

src/test/suite/languageServer/plugin.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe("Language server plugin", () => {
1515
)
1616
);
1717

18-
const fakeVscodeQuarkus: vscode.Extension<any> = {
18+
const fakeVscodeQuarkus: vscode.Extension<unknown> = {
1919
id: "fake-vscode-quarkus",
2020
extensionPath: "",
2121
extensionUri: vscode.Uri.parse("https://example.org"),
@@ -33,7 +33,7 @@ describe("Language server plugin", () => {
3333
)
3434
);
3535

36-
const fakeNoPluginExtension: vscode.Extension<any> = {
36+
const fakeNoPluginExtension: vscode.Extension<unknown> = {
3737
id: "fake-no-plugin-extension",
3838
extensionUri: vscode.Uri.parse("https://example.org"),
3939
extensionPath: "",

src/util/javaServerMode.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
import { window, commands } from "vscode";
2-
import { JavaExtensionAPI } from "../extension";
1+
import { commands, window } from "vscode";
2+
import { JavaExtensionAPI, ServerMode } from "../definitions/vscodeJavaApi";
33

44
export const JAVA_EXTENSION_ID = "redhat.java";
55

6-
export enum ServerMode {
7-
STANDARD = "Standard",
8-
LIGHTWEIGHT = "LightWeight",
9-
HYBRID = "Hybrid",
10-
}
11-
126
/**
137
* Waits for the java language server to launch in standard mode
148
* Before activating Tools for MicroProfile.

src/yaml/YamlSchema.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import * as vscode from 'vscode';
1716
import * as path from 'path';
1817
import * as semver from 'semver';
18+
import * as vscode from 'vscode';
1919

2020
import {
21-
VSCODE_YAML_EXTENSION_ID,
21+
MICROPROFILE_SCHEMA,
22+
MICROPROFILE_SCHEMA_PREFIX,
2223
VSCODE_YAML_DISPLAY_NAME,
23-
VSCODE_YAML_NOT_INSTALLED_MESSAGE,
24-
VSCODE_YAML_LOW_VERSION_MESSAGE,
25-
VSCODE_YAML_NO_REGISTRATION_MESSAGE,
24+
VSCODE_YAML_EXTENSION_ID,
2625
VSCODE_YAML_INSTALL_SUCCESS,
27-
MICROPROFILE_SCHEMA,
28-
MICROPROFILE_SCHEMA_PREFIX
26+
VSCODE_YAML_LOW_VERSION_MESSAGE,
27+
VSCODE_YAML_NOT_INSTALLED_MESSAGE,
28+
VSCODE_YAML_NO_REGISTRATION_MESSAGE
2929
} from "./YamlConstants";
3030

3131
import { Uri } from 'vscode';
@@ -112,7 +112,7 @@ const yamlSchemaCache = new YamlSchemaCache();
112112
let listener: vscode.Disposable|undefined = undefined;
113113

114114
export async function registerYamlSchemaSupport(){
115-
const yamlPlugin: any = await activateYamlExtension();
115+
const yamlPlugin = await activateYamlExtension();
116116
if (!yamlPlugin || !yamlPlugin.registerContributor) {
117117
// activateYamlExtension has already alerted users about errors.
118118
return undefined;
@@ -123,7 +123,7 @@ export async function registerYamlSchemaSupport(){
123123

124124
// find redhat.vscode-yaml extension and try to activate it to get the yaml contributor
125125
// this function should only be called once when vscode-microprofile activates
126-
async function activateYamlExtension(): Promise<{ registerContributor: YamlSchemaContributor } | undefined> {
126+
async function activateYamlExtension(): Promise<{ registerContributor?: YamlSchemaContributor } | undefined> {
127127
const ext = vscode.extensions.getExtension(VSCODE_YAML_EXTENSION_ID);
128128
const isApplicationYamlOpened: boolean = isEditorApplicationYaml(vscode.window.activeTextEditor);
129129

0 commit comments

Comments
 (0)