Skip to content

Commit

Permalink
chore: code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Jan 4, 2023
1 parent a07e2e5 commit 6fb0d73
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/CompletionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class JBangCompletionProvider implements CompletionItemProvider<Completio
context.subscriptions.push(
languages.registerCompletionItemProvider(languageId, this, ":", "/", "-")
);
})
});
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/DocumentationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const DOC_CACHE = new LRUCache<string, MarkdownString>({
// how long to live in ms
ttl: 1000 * 60 * 10,// 10 min
sizeCalculation: (value: MarkdownString, key: string) => {
return 1
return 1;
},
// return stale items before removing from cache?
allowStale: false,
Expand Down
3 changes: 2 additions & 1 deletion src/JBangConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export namespace JBangSettings {

export class JBangConfig {

// eslint-disable-next-line @typescript-eslint/naming-convention
static CLEAN_WORKSPACE = 'java.clean.workspace';

oldJavaConfig: WorkspaceConfiguration = this.getJavaConfiguration();
Expand Down Expand Up @@ -57,7 +58,7 @@ export class JBangConfig {
const info = this.getJBangConfiguration().inspect(configName);
let scope = ConfigurationTarget.Global;
if (info?.workspaceValue !== undefined) {
scope = ConfigurationTarget.Workspace
scope = ConfigurationTarget.Workspace;
} else if (info?.workspaceFolderValue !== undefined) {
scope = ConfigurationTarget.WorkspaceFolder;
}
Expand Down
2 changes: 1 addition & 1 deletion src/JBangHoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import DocumentationProvider from "./DocumentationProvider";
import { SUPPORTED_LANGUAGES } from "./JBangUtils";
import { Dependency } from "./models/Dependency";

const DEPS = "//DEPS "
const DEPS = "//DEPS ";

export class JBangHoverProvider implements HoverProvider {

Expand Down
8 changes: 4 additions & 4 deletions src/completion/CompletionParticipant.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CompletionContext, CompletionItem, CompletionList, Position, TextDocument } from "vscode"
import { CancellationToken } from "vscode-languageclient"
import { Dependency } from "../models/Dependency"
import { CompletionContext, CompletionItem, CompletionList, Position, TextDocument } from "vscode";
import { CancellationToken } from "vscode-languageclient";
import { Dependency } from "../models/Dependency";

export class JBangCompletionItem extends CompletionItem {
dependency?: Dependency
dependency?: Dependency;
}

export interface CompletionParticipant {
Expand Down
2 changes: 1 addition & 1 deletion src/completion/DependencyCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const QUERY_CACHE = new LRUCache<string, CompletionList>({
// how long to live in ms
ttl: 1000 * 60 * 10,// 10 min
sizeCalculation: (value: CompletionList, key: string) => {
return 1
return 1;
},
// return stale items before removing from cache?
allowStale: false,
Expand Down
8 changes: 4 additions & 4 deletions src/completion/DirectivesCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export class DirectivesCompletion implements CompletionParticipant {

async provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken, context: CompletionContext): Promise<CompletionList | CompletionItem[]> {
const items: CompletionItem[] = [];
if (position.line == 0) {
if (position.line === 0) {
items.push({
label: "///usr/bin/env jbang \"$0\" \"$@\" ; exit $?",
kind: CompletionItemKind.Text,
detail: "JBang header"
})
});
}
const range = new Range(new Position(position.line, 0), position);
const scanner = new DirectiveScanner();
Expand Down Expand Up @@ -93,7 +93,7 @@ export class DirectivesCompletion implements CompletionParticipant {

class DirectiveScanner {

directives:string[] = []
directives:string[] = [];

found(directive: string): boolean {
return this.directives.includes(directive);
Expand All @@ -102,7 +102,7 @@ class DirectiveScanner {
scan(document: TextDocument) {
const checkedDirectives = [
JAVA, JAVAC_OPTIONS, COMPILE_OPTIONS, DESCRIPTION, CDS, GAV, JAVAAGENT, MANIFEST, JAVA_OPTIONS, RUNTIME_OPTIONS, NATIVE_OPTIONS, KOTLIN, GROOVY
]
];
const lines = document.getText().split(/\r?\n/);
for (let i = 0; i < lines.length && checkedDirectives.length > 0; i++) {
const line = lines[i];
Expand Down
4 changes: 2 additions & 2 deletions src/completion/JavaOptionsCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const JAVA_OPTIONS = "//JAVA_OPTIONS ";
const COMPILE_OPTIONS = "//COMPILE_OPTIONS ";
const RUNTIME_OPTIONS = "//RUNTIME_OPTIONS ";
const JAVA = "//JAVA ";
const DIRECTIVES = [COMPILE_OPTIONS, RUNTIME_OPTIONS, JAVA, JAVAC_OPTIONS, JAVA_OPTIONS]
const DIRECTIVES = [COMPILE_OPTIONS, RUNTIME_OPTIONS, JAVA, JAVAC_OPTIONS, JAVA_OPTIONS];
const JAVA_VERSIONS = [19, 17, 11, 8];
export class JavaOptionsCompletion implements CompletionParticipant {
applies(lineText: string, position: Position): boolean {
Expand All @@ -29,7 +29,7 @@ export class JavaOptionsCompletion implements CompletionParticipant {
const javaVersions = getJavaVersions();
let range: Range;
if (directive === JAVA) {
range = new Range(new Position(position.line, JAVA.length), new Position(position.line, lineText.length))
range = new Range(new Position(position.line, JAVA.length), new Position(position.line, lineText.length));
JAVA_VERSIONS.forEach((v, i) => {
const item = new CompletionItem(`${v}`, CompletionItemKind.Value);
item.sortText = `${i}`;
Expand Down
4 changes: 2 additions & 2 deletions src/completion/SourcesCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class SourcesCompletion implements CompletionParticipant {
return [];
}
const end = TextHelper.findEndPosition(lineText, position);
const range = new Range(start, end)
const range = new Range(start, end);

const dirContent = await fs.readdir(targetDir);
const baseName = path.basename(document.fileName);
Expand All @@ -60,7 +60,7 @@ export class SourcesCompletion implements CompletionParticipant {
const isDir = (await fs.lstat(path.join(targetDir, name))).isDirectory();
let command:Command|undefined;
if (isDir) {
command = { command: 'editor.action.triggerSuggest', title: 'Re-trigger completions...' }
command = { command: 'editor.action.triggerSuggest', title: 'Re-trigger completions...' };
}
return {
label: name + (isDir?'/':''),
Expand Down
4 changes: 2 additions & 2 deletions src/models/Dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ const HOME = os.homedir() ;
export class Dependency {

public getLocalFile(): string | undefined {
if (this.groupId == undefined || this.artifactId === undefined || this.version === undefined) {
if (this.groupId === undefined || this.artifactId === undefined || this.version === undefined) {
return undefined;
}
const splitGroupId = this.groupId?.replace(/\./g,'/');
return `${HOME}/.m2/repository/${splitGroupId}/${this.artifactId}/${this.version}/${this.artifactId}-${this.version}.pom`;
}

public getRemoteUrl(): string | undefined {
if (this.groupId == undefined || this.artifactId === undefined || this.version === undefined) {
if (this.groupId === undefined || this.artifactId === undefined || this.version === undefined) {
return undefined;
}
const splitGroupId = this.groupId?.replace(/\./g,'/');
Expand Down
1 change: 1 addition & 0 deletions src/utils/javaExtension.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { commands, extensions, ProgressLocation, window } from "vscode";
// alias for vscode-java's ExtensionAPI
export type JavaExtensionAPI = any;
Expand Down
3 changes: 2 additions & 1 deletion src/utils/shellUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable @typescript-eslint/naming-convention */
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { Terminal, env } from "vscode";
import { env, Terminal } from "vscode";
import { executeCommand } from "./cpUtils";

export enum WindowsShellType {
Expand Down
4 changes: 2 additions & 2 deletions src/wizards/multiStepsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class MultiStepInput {
disposables.push(workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
const configNames: string[] = configChanges.map((configChange: ConfigChangeCallback) => configChange.configName);
const configName: string|undefined = configNames.find((name: string) => event.affectsConfiguration(name));
if (!configName) return;
if (!configName) {return;}

configChanges.forEach((configChange: ConfigChangeCallback) => {
if (configChange.configName === configName) {
Expand Down Expand Up @@ -223,7 +223,7 @@ export class MultiStepInput {
disposables.push(workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
const configNames: string[] = configChanges.map((configChange: ConfigChangeCallback) => configChange.configName);
const configName: string|undefined = configNames.find((name: string) => event.affectsConfiguration(name));
if (!configName) return;
if (!configName) {return;}

configChanges.forEach((configChange: ConfigChangeCallback) => {
if (configChange.configName === configName) {
Expand Down
5 changes: 3 additions & 2 deletions src/wizards/templateExec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ export async function listTemplates(): Promise<JBangTemplate[]> {
shell: true,
env: {
...process.env,
// eslint-disable-next-line @typescript-eslint/naming-convention
"NO_COLOR": "true"
}
})
});
let templates: JBangTemplate[] = [];
const lines = data.toString().split(/\r?\n/);
for (let i = 0; i < lines.length; i++) {
Expand Down Expand Up @@ -52,5 +53,5 @@ function generateArgs(scriptGenState: ScriptGenState): string[] {
}
args.push("--force");
args.push(scriptGenState.scriptName);
return args
return args;
}

0 comments on commit 6fb0d73

Please sign in to comment.