-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support managing referenced libraries #213
Merged
Merged
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6e83b76
UpdateClasspath support in jdt.ls plugin side:
Vigilans 2db9a8d
Client side Controller support:
Vigilans 3b8f1c6
UI support for add/remove/refresh libraries
Vigilans ad3dbbe
Remove libraryWatcher & refactor disposable
Vigilans e774da7
Resolve some comments in review
Vigilans 4ec8dc0
Remove native-ext-loader dependency
Vigilans 939c1cd
Remove the check of whether the setting has been modified
Vigilans 82265f3
Update the description
Vigilans cda7d69
Remove the related items if the including array contains exculding ones
jdneo 2976ac0
Revert the when clause change
jdneo bd63274
Use .filter() to simplify the code
jdneo ceaf1e5
Fix the issue that windows cannot select both files and folders
jdneo dcfe0ee
Force the param: to false
jdneo f0026b7
Merge remote-tracking branch 'origin' into vigilans/referencedLibraries
jdneo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import * as fse from "fs-extra"; | ||
import * as _ from "lodash"; | ||
import { commands, Disposable, ExtensionContext, Uri, window, workspace, WorkspaceFolder } from "vscode"; | ||
import { instrumentOperation } from "vscode-extension-telemetry-wrapper"; | ||
import { Commands } from "../commands"; | ||
import { Jdtls } from "../java/jdtls"; | ||
import { Settings } from "../settings"; | ||
import { Utility } from "../utility"; | ||
import { DataNode } from "../views/dataNode"; | ||
|
||
export class LibraryController implements Disposable { | ||
|
||
private disposable: Disposable; | ||
|
||
public constructor(public readonly context: ExtensionContext) { | ||
this.disposable = Disposable.from( | ||
commands.registerCommand(Commands.JAVA_PROJECT_ADD_LIBRARIES, | ||
instrumentOperation(Commands.JAVA_PROJECT_ADD_LIBRARIES, (operationId: string, node: DataNode) => this.addLibraries())), | ||
commands.registerCommand(Commands.JAVA_PROJECT_REMOVE_LIBRARY, | ||
instrumentOperation(Commands.JAVA_PROJECT_REMOVE_LIBRARY, (operationId: string, node: DataNode) => this.removeLibrary(node.path))), | ||
commands.registerCommand(Commands.JAVA_PROJECT_REFRESH_LIBRARIES, | ||
instrumentOperation(Commands.JAVA_PROJECT_REFRESH_LIBRARIES, (operationId: string, node: DataNode) => this.refreshLibraries())), | ||
); | ||
} | ||
|
||
public dispose() { | ||
this.disposable.dispose(); | ||
} | ||
|
||
public async addLibraries(libraryGlobs?: string[]) { | ||
if (!libraryGlobs) { | ||
libraryGlobs = []; | ||
const workspaceFolder: WorkspaceFolder | undefined = Utility.getDefaultWorkspaceFolder(); | ||
const results: Uri[] | undefined = await window.showOpenDialog({ | ||
defaultUri: workspaceFolder && workspaceFolder.uri, | ||
canSelectFiles: true, | ||
canSelectFolders: true, | ||
canSelectMany: true, | ||
openLabel: "Select a jar file or directory to the project classpath", | ||
}); | ||
if (!results) { | ||
return; | ||
} | ||
libraryGlobs = await Promise.all(results.map(async (uri: Uri) => { | ||
const uriPath = workspace.asRelativePath(uri, false); | ||
return (await fse.stat(uri.fsPath)).isDirectory() ? `${uriPath}/**/*.jar` : uriPath; | ||
})); | ||
} | ||
const setting = Settings.referencedLibraries(); | ||
setting.include.push(...libraryGlobs); | ||
Settings.updateReferencedLibraries(setting); | ||
} | ||
|
||
public async removeLibrary(library: string) { | ||
const setting = Settings.referencedLibraries(); | ||
setting.exclude.push(workspace.asRelativePath(library)); | ||
Settings.updateReferencedLibraries(setting); | ||
} | ||
|
||
public async refreshLibraries(): Promise<void> { | ||
const workspaceFolder = Utility.getDefaultWorkspaceFolder(); | ||
if (workspaceFolder) { | ||
await Jdtls.refreshLibraries(workspaceFolder.uri.toString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simply push might not work in some scenario, like:
if the original setting is:
where the
junit-platform-console-standalone-1.5.2.jar
is the only jar in the lib folder.Now if I re-add the lib folder into the referenced libs, the exclude part won't be updated.