-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdebugserver.ts
More file actions
58 lines (50 loc) · 2.26 KB
/
Copy pathdebugserver.ts
File metadata and controls
58 lines (50 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { TextDocument, Uri, window, workspace } from 'coc.nvim';
import * as Commands from './commands';
import { IClassPath, IMainClassOption, MainMethodResult } from './protocol';
export async function resolveMainMethodCurrentFile(): Promise<IMainClassOption | undefined> {
const mainMethods = await resolveMainMethodsCurrentFile();
if (mainMethods.length === 1) {
return mainMethods[0];
} else if (mainMethods.length > 1) {
return await pickMainMethod(mainMethods);
}
return undefined;
}
export async function resolveMainMethodsCurrentFile(): Promise<MainMethodResult> {
const { document } = await workspace.getCurrentState();
return resolveMainMethod(document);
}
async function resolveMainMethod(document: TextDocument): Promise<MainMethodResult> {
const resourcePath = getJavaResourcePath(document);
return Commands.executeCommand(Commands.JAVA_RESOLVE_MAINMETHOD, resourcePath);
}
export async function resolveClassPathCurrentFile(): Promise<IClassPath> {
const mainMethod = await resolveMainMethodCurrentFile();
if (mainMethod) {
return resolveClassPathMainMethod(mainMethod);
}
return { modulePaths: [], classPaths: [] };
}
export async function resolveClassPathMainMethod(mainMethod: IMainClassOption): Promise<IClassPath> {
const classPath = await resolveClasspath(mainMethod.mainClass, mainMethod.projectName || '');
const [modulePaths, classPaths]: [string[], string[]] = classPath;
return { modulePaths, classPaths };
}
async function resolveClasspath(mainClass: string, projectName: string, scope?: string): Promise<[string[], string[]]> {
return Commands.executeCommand(Commands.JAVA_RESOLVE_CLASSPATH, mainClass, projectName, scope);
}
function getJavaResourcePath(document: TextDocument): string | undefined {
const resource = Uri.parse(document.uri);
if (resource.scheme === 'file' && resource.fsPath.endsWith('.java')) {
return resource.toString();
}
return undefined;
}
export async function pickMainMethod(mainMethods: MainMethodResult): Promise<IMainClassOption> {
const items = mainMethods.map((method) => {
return method.mainClass;
});
const selected = await window.showQuickpick(items, 'Choose a main method.');
// Choose the first one if none is selected.
return mainMethods[selected >= 0 ? selected : 0];
}