|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -import { ExtensionContext, window, workspace, commands, Uri, ProgressLocation, ViewColumn, EventEmitter, extensions, Location, languages, CodeActionKind, TextEditor, CancellationToken, ConfigurationTarget, Range, Position } from "vscode"; |
| 3 | +import { ExtensionContext, window, workspace, commands, Uri, ProgressLocation, ViewColumn, EventEmitter, extensions, Location, languages, CodeActionKind, TextEditor, CancellationToken, ConfigurationTarget, Range, Position, QuickPickItem } from "vscode"; |
4 | 4 | import { Commands } from "./commands";
|
5 | 5 | import { serverStatus, ServerStatusKind } from "./serverStatus";
|
6 | 6 | import { prepareExecutable, awaitServerConnection } from "./javaServerStarter";
|
@@ -585,23 +585,97 @@ function setIncompleteClasspathSeverity(severity: string) {
|
585 | 585 | );
|
586 | 586 | }
|
587 | 587 |
|
588 |
| -function projectConfigurationUpdate(languageClient: LanguageClient, uri?: Uri) { |
589 |
| - let resource = uri; |
590 |
| - if (!(resource instanceof Uri)) { |
591 |
| - if (window.activeTextEditor) { |
592 |
| - resource = window.activeTextEditor.document.uri; |
| 588 | +async function projectConfigurationUpdate(languageClient: LanguageClient, uris?: Uri | Uri[]) { |
| 589 | + let resources = []; |
| 590 | + if (!uris) { |
| 591 | + resources = await askForProjectToUpdate(); |
| 592 | + } else if (uris instanceof Uri) { |
| 593 | + resources.push(uris); |
| 594 | + } else if (Array.isArray(uris)) { |
| 595 | + for (const uri of uris) { |
| 596 | + if (uri instanceof Uri) { |
| 597 | + resources.push(uri); |
| 598 | + } |
593 | 599 | }
|
594 | 600 | }
|
595 |
| - if (!resource) { |
596 |
| - return window.showWarningMessage('No Java project to update!').then(() => false); |
597 |
| - } |
598 |
| - if (isJavaConfigFile(resource.path)) { |
| 601 | + if (resources.length === 1) { |
599 | 602 | languageClient.sendNotification(ProjectConfigurationUpdateRequest.type, {
|
600 |
| - uri: resource.toString() |
| 603 | + uri: resources[0].toString(), |
| 604 | + }); |
| 605 | + } else if (resources.length > 1) { |
| 606 | + languageClient.sendNotification(ProjectConfigurationUpdateRequest.typeV2, { |
| 607 | + identifiers: resources.map(r => { |
| 608 | + return { uri: r.toString() }; |
| 609 | + }), |
601 | 610 | });
|
602 | 611 | }
|
603 | 612 | }
|
604 | 613 |
|
| 614 | +async function askForProjectToUpdate(): Promise<Uri[]> { |
| 615 | + let uriCandidate: Uri; |
| 616 | + if (window.activeTextEditor) { |
| 617 | + uriCandidate = window.activeTextEditor.document.uri; |
| 618 | + } |
| 619 | + |
| 620 | + if (uriCandidate && isJavaConfigFile(uriCandidate.fsPath)) { |
| 621 | + return [uriCandidate]; |
| 622 | + } |
| 623 | + |
| 624 | + let projectUriStrings: string[]; |
| 625 | + try { |
| 626 | + projectUriStrings = await commands.executeCommand<string[]>(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.GET_ALL_JAVA_PROJECTS); |
| 627 | + } catch (e) { |
| 628 | + return uriCandidate ? [uriCandidate] : []; |
| 629 | + } |
| 630 | + |
| 631 | + const projectPicks: QuickPickItem[] = projectUriStrings.map(uriString => { |
| 632 | + const projectPath = Uri.parse(uriString).fsPath; |
| 633 | + if (path.basename(projectPath) === "jdt.ls-java-project") { |
| 634 | + return undefined; |
| 635 | + } |
| 636 | + |
| 637 | + return { |
| 638 | + label: path.basename(projectPath), |
| 639 | + detail: projectPath, |
| 640 | + }; |
| 641 | + }).filter(Boolean); |
| 642 | + |
| 643 | + if (projectPicks.length === 0) { |
| 644 | + return []; |
| 645 | + } else if (projectPicks.length === 1) { |
| 646 | + return [Uri.file(projectPicks[0].detail)]; |
| 647 | + } else { |
| 648 | + // pre-select an active project based on the uri candidate. |
| 649 | + if (uriCandidate) { |
| 650 | + const candidatePath = uriCandidate.fsPath; |
| 651 | + let belongingIndex = -1; |
| 652 | + for (let i = 0; i < projectPicks.length; i++) { |
| 653 | + if (candidatePath.startsWith(projectPicks[i].detail)) { |
| 654 | + if (belongingIndex < 0 |
| 655 | + || projectPicks[i].detail.length > projectPicks[belongingIndex].detail.length) { |
| 656 | + belongingIndex = i; |
| 657 | + } |
| 658 | + } |
| 659 | + } |
| 660 | + if (belongingIndex >= 0) { |
| 661 | + projectPicks[belongingIndex].picked = true; |
| 662 | + } |
| 663 | + } |
| 664 | + |
| 665 | + const choices: QuickPickItem[] | undefined = await window.showQuickPick(projectPicks, { |
| 666 | + matchOnDetail: true, |
| 667 | + placeHolder: "Please select the project(s) to update.", |
| 668 | + ignoreFocusOut: true, |
| 669 | + canPickMany: true, |
| 670 | + }); |
| 671 | + if (choices && choices.length) { |
| 672 | + return choices.map(c => Uri.file(c.detail)); |
| 673 | + } |
| 674 | + } |
| 675 | + |
| 676 | + return []; |
| 677 | +} |
| 678 | + |
605 | 679 | function isJavaConfigFile(filePath: string) {
|
606 | 680 | const fileName = path.basename(filePath);
|
607 | 681 | const regEx = new RegExp(buildFilePatterns.map(r => `(${r})`).join('|'), 'i');
|
|
0 commit comments