-
Notifications
You must be signed in to change notification settings - Fork 915
Java LSP server: Associate a single source file with an available workspace with no client workspace folders in order to obtain the configured options #7610
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
Conversation
|
Hi @mbien. Please review this PR and/or assign other reviewers, as per your convenience. Thanks. |
|
@sid-srini I pinged a few who might be able to review this. |
|
Overall, this makes sense to me. But I am thinking, what if I open a file from outside of the workspace. So, what if, just before the new code here, we would check if there's exactly one workspace, and if there is, we would use the single workspace. (Keeping the pre-existing code computing the workspace folders, as that is needed as a default working directory.) Having one workspace should be the typical thing. What do you think? |
|
Thank you @lahodaj for reviewing the PR.
Yes, having one workspace is the typical use-case.
When I was adding this new code, my concern with this approach of defaulting to the single open workspace was that it may lead to a security/cross-talk issue if someone opens a file external to the regular workspace (with workspace folders).
Do you think that in case no suitable workspace is found, then this method should introduce adding a new
Please let me know what you think. Thank you. |
Note that the current default is that for every workspace/VS Code UI window, there is a separate backend started. I.e. this is not about the number of windows open, but rather whether the backend is shared by multiple windows, which is not the default.
Isn't that a problem with this patch as well? If the backend is shared among multiple windows, and I have multiple windows with workspaces without folders, this patch will pick one of the UI windows/settings/clients semi-"randomly", no?
I suspect the same will be with this patch - if the backend is shared among windows, then one of then will be selected, no? And if the backend is not shared, then there's only one workspace, and all should work consistently?
The Workspace is basically just a part of the mirror that mirrors the UI Window. I don't think we can meaningfully create a new one.
|
|
Thanks @lahodaj for the explanation of the concrete implementation context. The key differentiation in the patch is that a workspace with no folders is chosen to associate the single-file with.
The contrast scenario for this is to associate the single-file with a workspace having one-or-more folders.
Does that make sense? |
|
(I might have diverged a bit in my previous comment, so sorry for that.) I guess I don't see the problem with "leaking" some settings to a file that the user explicitly ran in the same window as the settings are defined. Not quite clear to me what's the problem with that - the user wants to run the file, and we read the relevant settings in the given window. With the current proposed patch, if I open a file Also note that with the current patch, (I believe) I can have a file open in window 1 and ran from there, but settings may be taken from window 2, just because window 2's workspace has no folders. Whether the settings are global or not does not seem all too relevant to me. All in all, I wonder if we should simply permit out-of-workspace files with settings only when there's a single workspace (as then we can reliably say which workspace to use and we know the backend is attached to exactly one workspace/window), and keep the current behavior if we there are multiple workspaces. |
|
Understood. It makes sense to keep this simple. I'll revise the patch and add to this PR. Thank you very much @lahodaj. |
|
I've pushed the patch incorporating the suggestion above by @lahodaj. Please review. Thanks. |
...er/src/org/netbeans/modules/java/lsp/server/singlesourcefile/SingleFileOptionsQueryImpl.java
Outdated
Show resolved
Hide resolved
lahodaj
left a comment
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.
Functionally OK, I think. Stylistically, I would probably try to avoid the count, but it is not so easy, so I guess I am mostly fine with that.
|
don't forget to squash before merge |
c1a9c0b to
f77b59a
Compare
Thanks @mbien. I've squashed the commits. |
Backporting the NetBeans 24 patch [#7610](apache/netbeans#7610) and adding it to the patches list in build.xml. - This brings the fix for getting config options for a single source file to the NB 22 branch. - This allows the fix for oracle#199 to demonstrate its effect. Signed-off-by: Siddharth Srinivasan <siddharth.srinivasan@oracle.com>
* [JVSC #199] Backport NetBeans 24 patch 7610 Backporting the NetBeans 24 patch [#7610](apache/netbeans#7610) and adding it to the patches list in build.xml. - This brings the fix for getting config options for a single source file to the NB 22 branch. - This allows the fix for #199 to demonstrate its effect. Signed-off-by: Siddharth Srinivasan <siddharth.srinivasan@oracle.com> * Update build.xml with ascending numeric order of PR patches Signed-off-by: Siddharth Srinivasan <siddharth.srinivasan@oracle.com> --------- Signed-off-by: Siddharth Srinivasan <siddharth.srinivasan@oracle.com>
|
Requesting a merge of this PR. Thank you. |
|
Would someone please re-open this PR and merge it for NB24? |
|
Requesting a merge of this PR. Thank you. |
|
@mbien Requesting a merge of this PR. Thank you. |
@mbien Requesting a merge of this PR. Thank you. |
|
Hi @sid-srini, I am not involved in the VSCode extension. I saw this PR and only mentioned squashing as a reminder since we had some accidental merges around that time. (thanks for squashing!) But since the last CI run was a while ago, it would be good to rebase it on top of latest master (again) for a fresh CI run - since a lot happened including the repo-wide spec bump. I am sure one of the reviewers will be able to merge once the time is right - not sure why its still open - this repo has two schedules which might be a reason. |
f77b59a to
d31294f
Compare
Thanks @mbien. I've pushed the commit rebased against the latest master. If possible, kindly trigger the CI build. |
|
@sid-srini thanks! CI is already running. |
d31294f to
5ecd832
Compare
|
Unless there are objections, I'll integrate sometime soon. |
|
@sid-srini could you rebase this PR since a lot happened in the last ~3 weeks. thanks! |
…kspace with no client workspace folders in order to obtain the configured options
Issue:
------
When a single-source file is opened in a workspace with no workspace folders, the global workspace options need to be made available to the operations done on that file.
- In apache#7382, SingleFileOptionsQueryImpl introduced search for a single source file's parent in open workspaces' folders.
- However, when setConfiguration() is invoked with null workDirectory, the options for the workspace are not made available to single-source files which are outside any workspace folders.
Fix:
----
1. Fixed SingleFileOptionsQueryImpl.optionsFor():
- to: associate a single-source file's parent with a workspace that is the only open workspace,
- when: it has no associated workspace folder.
2. Updated the associated unit tests in SingleFileOptionsQueryImplTest.
3. Added checks for null and ConcurrentModificationException when iterating over the workspace2Settings Map (which is a WeakHashMap).
4. Incorporated the review suggestion to perform a workspaces set copy in the synchronized block of SingleFileOptionsQueryImpl.optionsFor();
- in place of a try-catch of ConcurrentModificationException.
Signed-off-by: Siddharth Srinivasan <siddharth.srinivasan@oracle.com>
5ecd832 to
d27d435
Compare
Sure. I've rebased onto the current master. Thanks @lahodaj and @mbien. |
Java LSP server: Associate a single source file with an available workspace with no client workspace folders in order to obtain the configured options
Issue
SingleFileOptionsQueryImplintroduced search for a single source file's parent in open workspaces' folders.setConfiguration()is invoked withnullworkDirectory, the options for the workspace are not made available to single-source files which are outside any workspace folders.Effect
Errors such as those resolved by vmOptions such as
--enable-previewor a--source <version>continue to be flagged even when the single-source file can be run successfully.Fix
SingleFileOptionsQueryImpl.optionsFor():SingleFileOptionsQueryImplTest.