Skip to content

Commit

Permalink
Resolve new linting issues
Browse files Browse the repository at this point in the history
Signed-off-by: David Thompson <[email protected]>
  • Loading branch information
datho7561 committed Apr 12, 2024
1 parent e455069 commit 5935cc0
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 49 deletions.
40 changes: 40 additions & 0 deletions src/definitions/vscodeJavaApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright 2024 Red Hat, Inc. and others.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type { Event } from "vscode";

/**
* @see https://github.com/redhat-developer/vscode-java/blob/master/src/extension.api.ts#L116
*/
export type JavaExtensionAPI = {
serverMode: ServerMode;
readonly javaRequirement: RequirementsData;
readonly onDidServerModeChange: Event<ServerMode>;
readonly serverReady: () => Promise<boolean>;
};

export enum ServerMode {
STANDARD = "Standard",
LIGHTWEIGHT = "LightWeight",
HYBRID = "Hybrid",
}

/* eslint-disable @typescript-eslint/naming-convention */
export interface RequirementsData {
tooling_jre: string;
tooling_jre_version: number;
java_home: string;
java_version: number;
}
12 changes: 5 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { getRedHatService, TelemetryService } from '@redhat-developer/vscode-redhat-telemetry/lib';
import { RedHatService } from '@redhat-developer/vscode-redhat-telemetry';
import { CodeAction as VSCodeAction, CodeActionKind, Command as VSCommand, commands, Diagnostic as VSDiagnostic, ExtensionContext, extensions, window, workspace, TextDocument, FileCreateEvent } from 'vscode';
import { getRedHatService, TelemetryService } from '@redhat-developer/vscode-redhat-telemetry/lib';
import { CodeActionKind, commands, ExtensionContext, extensions, FileCreateEvent, TextDocument, CodeAction as VSCodeAction, Command as VSCommand, Diagnostic as VSDiagnostic, window, workspace } from 'vscode';
import { CancellationToken, CodeAction, CodeActionResolveRequest, Command, DidChangeConfigurationNotification, DocumentSelector, LanguageClientOptions, RequestType } from 'vscode-languageclient';
import { LanguageClient } from 'vscode-languageclient/node';
import { APPLY_CODE_ACTION_WITH_TELEMETRY } from './definitions/commands';
import * as CommandKind from './definitions/lspCommandKind';
import * as MicroProfileLS from './definitions/microProfileLSRequestNames';
import { JavaExtensionAPI } from './definitions/vscodeJavaApi';
import { prepareExecutable } from './languageServer/javaServerStarter';
import { collectMicroProfileJavaExtensions, handleExtensionChange, MicroProfileContribution } from './languageServer/plugin';
import { resolveRequirements } from './languageServer/requirements';
import { registerConfigurationUpdateCommand, registerOpenURICommand } from './lsp-commands';
import { JAVA_EXTENSION_ID, waitForStandardMode } from './util/javaServerMode';
import { sendCodeActionTelemetry } from './util/telemetry';
import { getFilePathsFromWorkspace } from './util/workspaceUtils';
import { MicroProfilePropertiesChangeEvent, registerYamlSchemaSupport, YamlSchemaCache, getYamlSchemaCache } from './yaml/YamlSchema';
import { getYamlSchemaCache, MicroProfilePropertiesChangeEvent, registerYamlSchemaSupport, YamlSchemaCache } from './yaml/YamlSchema';

let languageClient: LanguageClient;

// alias for vscode-java's ExtensionAPI
export type JavaExtensionAPI = any;

export async function activate(context: ExtensionContext): Promise<void> {
if (await isJavaProject()) {
await doActivate(context);
Expand Down Expand Up @@ -296,7 +294,7 @@ async function connectToLS(context: ExtensionContext, api: JavaExtensionAPI, doc
* Returns a json object with key 'microprofile' and a json object value that
* holds all microprofile settings.
*/
function getVSCodeMicroProfileSettings(): { microprofile: any } {
function getVSCodeMicroProfileSettings(): { microprofile } {
const defaultMicroProfileSettings = {};
const configMicroProfile = workspace.getConfiguration().get('microprofile');
const microprofileSettings = configMicroProfile ? configMicroProfile : defaultMicroProfileSettings;
Expand Down
2 changes: 1 addition & 1 deletion src/languageServer/javaServerStarter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as os from 'os';
import * as path from 'path';
import { workspace } from 'vscode';
import { Executable, ExecutableOptions } from 'vscode-languageclient/node';
import { RequirementsData } from './requirements';
import { RequirementsData } from '../definitions/vscodeJavaApi';

const DEBUG = startedInDebugMode();
const DEBUG_PORT = 1064;
Expand Down
18 changes: 9 additions & 9 deletions src/languageServer/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as vscode from 'vscode';
import * as path from 'path';
import * as Commands from '../definitions/commands';
import { DocumentFilter, DocumentSelector } from 'vscode-languageclient';
import { isDeepStrictEqual } from 'util';
import * as vscode from 'vscode';
import { DocumentFilter, DocumentSelector, TextDocumentFilter } from 'vscode-languageclient';
import * as Commands from '../definitions/commands';

let existingExtensions: MicroProfileContribution[];

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

export function handleExtensionChange(extensions: readonly vscode.Extension<any>[]): void {
export function handleExtensionChange(extensions: readonly vscode.Extension<unknown>[]): void {
if (!existingExtensions) {
return;
}
Expand Down Expand Up @@ -78,20 +78,20 @@ export function handleExtensionChange(extensions: readonly vscode.Extension<any>
}
}

function setJarExtensionsIfExists(obj: MicroProfileContribution, section: any, extensionPath: string): void {
function setJarExtensionsIfExists(obj: MicroProfileContribution, section: { jarExtensions: string[]; }, extensionPath: string): void {
if (Array.isArray(section.jarExtensions)) {
for (const microprofileJavaExtensionPath of section.jarExtensions) {
obj.jarExtensions.push(path.resolve(extensionPath, microprofileJavaExtensionPath));
}
}
}

function setDocumentSelectorIfExists(obj: MicroProfileContribution, section: any): void {
if (!Array.isArray(section.documentSelector)) {
function setDocumentSelectorIfExists(obj: MicroProfileContribution, section: { documentSelector: (string | TextDocumentFilter)[]; }): void {
if (!section.documentSelector || !Array.isArray(section.documentSelector)) {
return;
}
const documentSelector: DocumentSelector = [];
section.documentSelector.forEach((selector: any) => {
section.documentSelector.forEach((selector) => {
if (typeof selector === 'string') {
documentSelector.push(selector);
} else if (selector) {
Expand Down
11 changes: 2 additions & 9 deletions src/languageServer/requirements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@ import * as path from 'path';
import { Uri, workspace } from 'vscode';

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

export interface RequirementsData {
tooling_jre: string;
tooling_jre_version: number;
java_home: string;
java_version: number;
}

/**
* Resolves the requirements needed to run the extension.
* Returns a promise that will resolve to a RequirementsData if
Expand Down
2 changes: 1 addition & 1 deletion src/lsp-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function addToPreferenceArray<T>(key: string, value: T): void {

interface ConfigurationItemEdit {
section: string;
value: any;
value;
editType: ConfigurationItemEditType;
}

Expand Down
9 changes: 4 additions & 5 deletions src/test/suite/languageServer/documentSelectorPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { expect } from "chai";
import * as vscode from "vscode";
import { DocumentSelector, TextDocumentFilter } from "vscode-languageclient";
import * as plugin from "../../../languageServer/plugin";
import { expect } from "chai";
import { MicroProfileContribution } from "../../../languageServer/plugin";
import { TextDocumentFilter, DocumentSelector } from "vscode-languageclient";

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

const selector: DocumentSelector = contribution[0].documentSelector;
return contribution[0].documentSelector;
}
});
10 changes: 2 additions & 8 deletions src/util/javaServerMode.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { window, commands } from "vscode";
import { JavaExtensionAPI } from "../extension";
import { commands, window } from "vscode";
import { JavaExtensionAPI, ServerMode } from "../definitions/vscodeJavaApi";

export const JAVA_EXTENSION_ID = "redhat.java";

export enum ServerMode {
STANDARD = "Standard",
LIGHTWEIGHT = "LightWeight",
HYBRID = "Hybrid",
}

/**
* Waits for the java language server to launch in standard mode
* Before activating Tools for MicroProfile.
Expand Down
18 changes: 9 additions & 9 deletions src/yaml/YamlSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as vscode from 'vscode';
import * as path from 'path';
import * as semver from 'semver';
import * as vscode from 'vscode';

import {
VSCODE_YAML_EXTENSION_ID,
MICROPROFILE_SCHEMA,
MICROPROFILE_SCHEMA_PREFIX,
VSCODE_YAML_DISPLAY_NAME,
VSCODE_YAML_NOT_INSTALLED_MESSAGE,
VSCODE_YAML_LOW_VERSION_MESSAGE,
VSCODE_YAML_NO_REGISTRATION_MESSAGE,
VSCODE_YAML_EXTENSION_ID,
VSCODE_YAML_INSTALL_SUCCESS,
MICROPROFILE_SCHEMA,
MICROPROFILE_SCHEMA_PREFIX
VSCODE_YAML_LOW_VERSION_MESSAGE,
VSCODE_YAML_NOT_INSTALLED_MESSAGE,
VSCODE_YAML_NO_REGISTRATION_MESSAGE
} from "./YamlConstants";

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

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

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

Expand Down

0 comments on commit 5935cc0

Please sign in to comment.