-
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
Fix add libraries dialog not working on Linux #434
Conversation
Not sure why the test failed on Linux, the errors in the log don't seem to be related to the changes in this PR. And I've ran the tests successfully on my development machine (running Debian 10). |
Thank you @0dinD, I'll take a look! |
@0dinD Thank you for the detailed explanation. And the fix looks promising! To me, personally I prefer the way 30ab944 does for this issue. b2d3702 is also great, but it introduces a new command and buttons . I'm not sure how users can easily get the point between So I tend to keep it simple:
But, we can definitely revisit this if we see more and more users are asking adding folder support on Linux and Windows. What do you think? |
@jdneo I do agree that keeping it simple is preferable over adding a new button. An alternative solution that I just came to think of is to make the We could also add both commands to the context menu of |
@0dinD I think that's a good idea. Will you update the PR for that? |
@jdneo I'll update the PR later today. But since it still requires two separate commands, I do still need translations for the new command titles. Are you able to help with that? |
No worry, I'll append my commit to this PR :) |
OK, I've addressed the changes we discussed in 4665d8c. Note that on Linux, |
src/controllers/libraryController.ts
Outdated
const setting = Settings.referencedLibraries(); | ||
setting.exclude = this.dedupAlreadyCoveredPattern(libraryGlobs, ...setting.exclude); | ||
setting.include = this.updatePatternArray(setting.include, ...libraryGlobs); | ||
Settings.updateReferencedLibraries(setting); | ||
} | ||
|
||
public async addLibraries(folders?: boolean) { |
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.
Change the param name to canSelectFolders
to just align with the API?
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.
Makes sense, fixed in a735dc5.
src/controllers/libraryController.ts
Outdated
const results: Uri[] | undefined = await window.showOpenDialog({ | ||
defaultUri: workspaceFolder && workspaceFolder.uri, | ||
canSelectFiles: !folders, | ||
canSelectFolders: folders, |
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.
One possible regression here is: for the Mac users, they actually lose the capability to select both files and folders in one dialog.
So maybe still also check if it is in MacOS?
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.
I actually think it's better for the sake of simplicity to keep folder selection specific to the more advanced alt command. Since I don't think we can change the command title based on OS (without creating a third command that only displays on macOS), there is no consistent way to communicate with the user that both Jar files and folders can be selected when running macOS. However, I do agree that removing the capability is a regression (which might bother some users), so I added back folder selection to the addLibraries
dialog on macOS in a735dc5.
src/controllers/libraryController.ts
Outdated
// keep the param: `includeWorkspaceFolder` to false here | ||
// since the multi-root is not supported well for invisible projects | ||
const uriPath = workspace.asRelativePath(uri, false); | ||
return canSelectFolders ? uriPath + "/**/*.jar" : uriPath; |
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.
When it's on MacOS, and triggered from addLibraries
(canSelectFolders
is undefined
), if the user selects a folder, then it will not append /**/*.jar
.
So maybe we still need the previous logic -- check if it is a folder or not and return different value accordingly.
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.
Good catch! I missed that since I don't have a mac to test on, but I'll add the old logic back.
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.
Fixed in 2197367 (although I can't test if it works, since I don't have a mac).
Chinese translation added. BTW, I update |
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.
Verified on Mac and Windows, all works fine!
Thank you @0dinD !
No problem, glad I could help! FYI @jdneo the issue fixed in this PR seems to be related to a recent negative review on the Java Extension Pack and the Language Support for Java extension. I can see you've already referenced this PR on the review left on this extension, but it would probably be a good idea to respond to all reviews (even though they're from the same user), as it might help others. I don't know about the extension pack, but I'm guessing @fbricon or @rgrunber is responsible for the Java extension. |
Fixes #238
When trying to add a library to
Referenced Libraries
for invisible projects on Linux, all files are grayed out (unselectable), and you can't even navigate into folders. This makes it impossible to add libraries for invisible projects on Linux, unless you modify the settings.json manually.This is caused by the unclear API docs for OpenDialogOptions, which say:
This extension then assumes that
canSelectFiles
andcanSelectFolders
can be activated at the same time on both macOS and Linux - but it's actually unsupported on both Windows and Linux (which is the root cause of the issue).Behind the scenes, VS Code is using the Electron API to show the file dialog, and the whole situation actually becomes much clearer if you read the Electron docs for
dialog
:So what currently happens is that this extension requests a file dialog that can select both files and folders on Linux, which Electron then converts to a file dialog that can only select folders. That means you can't select any Jar files, and you also can't select (or navigate into) any folders, because they don't match the
jar
file filter.30ab944 is a very simple fix that just makes sure to only offer directory selection on macOS.
But after implementing this, I felt like it was a bit of a shame that Windows and Linux users were missing this QOL feature, just because of some Electron or OS limitation. So in b2d3702 I added a separate button for adding folders to the
Referenced Libraries
, so that users can also add library folders on Windows and Linux.Let me know if these changes sound good, and if the naming makes sense for all the buttons/tooltips. I would also like some help with the Chinese translation for the new/updated button tooltips, since I don't know any (and I don't really trust Google Translate to do a good job).