Skip to content

Commit ab3e745

Browse files
authored
Skip default project when detecting lombok (#2633)
* Extract utility to filter default project when getting all java projects Signed-off-by: Sheng Chen <[email protected]>
1 parent b7fd9dc commit ab3e745

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

src/lombokSupport.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { apiManager } from "./apiManager";
1010
import { supportsLanguageStatus } from "./languageStatusItemFactory";
1111
import { runtimeStatusBarProvider } from './runtimeStatusBarProvider';
1212
import { logger } from './log';
13+
import { getAllJavaProjects } from "./utils";
1314

1415
export const JAVA_LOMBOK_PATH = "java.lombokPath";
1516

@@ -126,7 +127,7 @@ export async function checkLombokDependency(context: ExtensionContext) {
126127
let currentLombokVersion: string = undefined;
127128
let previousLombokVersion: string = undefined;
128129
let currentLombokClasspath: string = undefined;
129-
const projectUris: string[] = await commands.executeCommand<string[]>(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.GET_ALL_JAVA_PROJECTS);
130+
const projectUris: string[] = await getAllJavaProjects();
130131
for (const projectUri of projectUris) {
131132
const classpathResult = await apiManager.getApiInstance().getClasspaths(projectUri, {scope: 'test'});
132133
for (const classpath of classpathResult.classpaths) {

src/runtimeStatusBarProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { apiManager } from "./apiManager";
99
import * as semver from "semver";
1010
import { ACTIVE_BUILD_TOOL_STATE } from "./settings";
1111
import { BuildFileStatusItemFactory, RuntimeStatusItemFactory, StatusCommands, supportsLanguageStatus } from "./languageStatusItemFactory";
12-
import { getJavaConfiguration } from "./utils";
12+
import { getAllJavaProjects, getJavaConfiguration } from "./utils";
1313
import { hasBuildToolConflicts } from "./extension";
1414
import { LombokVersionItemFactory, getLombokVersion, isLombokImported } from "./lombokSupport";
1515

@@ -51,7 +51,7 @@ class RuntimeStatusBarProvider implements Disposable {
5151

5252
let projectUriStrings: string[];
5353
try {
54-
projectUriStrings = await commands.executeCommand<string[]>(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.GET_ALL_JAVA_PROJECTS);
54+
projectUriStrings = await getAllJavaProjects(false);
5555
} catch (e) {
5656
return;
5757
}

src/standardLanguageClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { getJdkUrl, RequirementsData, sortJdksBySource, sortJdksByVersion } from
1515
import * as net from 'net';
1616
import * as fse from 'fs-extra';
1717
import * as path from 'path';
18-
import { getJavaConfiguration } from "./utils";
18+
import { getAllJavaProjects, getJavaConfiguration } from "./utils";
1919
import { logger } from "./log";
2020
import * as buildPath from './buildpath';
2121
import * as sourceAction from './sourceAction';
@@ -609,8 +609,8 @@ async function showImportFinishNotification(context: ExtensionContext) {
609609
options.unshift("Show errors");
610610
choice = await window.showWarningMessage("Errors occurred during import of Java projects.", ...options);
611611
} else {
612-
const projectUris: string[] = await commands.executeCommand<string[]>(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.GET_ALL_JAVA_PROJECTS);
613-
if (projectUris.length === 0 || (projectUris.length === 1 && projectUris[0].includes("jdt.ls-java-project"))) {
612+
const projectUris: string[] = await getAllJavaProjects();
613+
if (projectUris.length === 0) {
614614
return;
615615
}
616616

src/standardLanguageClientUtils.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { LanguageClient } from "vscode-languageclient/node";
88
import { buildFilePatterns } from "./plugin";
99
import { ProjectConfigurationUpdateRequest } from "./protocol";
1010
import { Commands } from "./commands";
11+
import { getAllJavaProjects } from "./utils";
1112

1213
export async function projectConfigurationUpdate(languageClient: LanguageClient, uris?: TextDocumentIdentifier | Uri | Uri[]) {
1314
let resources = [];
@@ -85,17 +86,13 @@ export async function askForProjects(activeFileUri: Uri | undefined, placeHolder
8586
async function generateProjectPicks(activeFileUri: Uri | undefined): Promise<QuickPickItem[] | undefined> {
8687
let projectUriStrings: string[];
8788
try {
88-
projectUriStrings = await commands.executeCommand<string[]>(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.GET_ALL_JAVA_PROJECTS);
89+
projectUriStrings = await getAllJavaProjects();
8990
} catch (e) {
9091
return undefined;
9192
}
9293

9394
const projectPicks: QuickPickItem[] = projectUriStrings.map(uriString => {
9495
const projectPath = Uri.parse(uriString).fsPath;
95-
if (path.basename(projectPath) === "jdt.ls-java-project") {
96-
return undefined;
97-
}
98-
9996
return {
10097
label: path.basename(projectPath),
10198
detail: projectPath,

src/utils.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import * as fs from 'fs';
44
import * as path from 'path';
5-
import { workspace, WorkspaceConfiguration, TextDocument } from 'vscode';
5+
import { workspace, WorkspaceConfiguration, TextDocument, commands, Uri } from 'vscode';
6+
import { Commands } from './commands';
67

78
export function getJavaConfiguration(): WorkspaceConfiguration {
89
return workspace.getConfiguration('java');
@@ -115,3 +116,19 @@ function parseToStringGlob(patterns: string[]): string {
115116

116117
return `{${patterns.join(",")}}`;
117118
}
119+
120+
/**
121+
* Get all Java projects from Java Language Server.
122+
* @param excludeDefaultProject whether the default project should be excluded from the list, defaults to true.
123+
* @returns string array for the project uris.
124+
*/
125+
export async function getAllJavaProjects(excludeDefaultProject: boolean = true): Promise<string[]> {
126+
let projectUris: string[] = await commands.executeCommand<string[]>(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.GET_ALL_JAVA_PROJECTS);
127+
if (excludeDefaultProject) {
128+
projectUris = projectUris.filter((uriString) => {
129+
const projectPath = Uri.parse(uriString).fsPath;
130+
return path.basename(projectPath) !== "jdt.ls-java-project";
131+
});
132+
}
133+
return projectUris;
134+
}

0 commit comments

Comments
 (0)