Skip to content

Rework JDT completions via LSP - #1238

Merged
mickaelistria merged 2 commits into
eclipse-lsp4e:mainfrom
BoykoAlex:jdt-completions
Apr 4, 2025
Merged

mickaelistria merged 2 commits into
eclipse-lsp4e:mainfrom
BoykoAlex:jdt-completions

Conversation

@BoykoAlex

@BoykoAlex BoykoAlex commented Apr 2, 2025 •

Copy link
Copy Markdown
Contributor

Rework naive implementation of LSP completions for Java Editor

@martinlippert martinlippert left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried the changes with our Spring Boot language server in the various situations where we use Spring completions inside of Java source code, seems to work nicely.

public StyledString getStyledDisplayString() {
if (Boolean.TRUE.equals(item.getDeprecated())) {
return new StyledString(getDisplayString(), StyleUtil.DEPRECATE);
StyledString ss = Boolean.TRUE.equals(item.getDeprecated())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you mind doing this part of the PR (which I think adds support for completion label details) in a separate PR? That part should be very easy to review then.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

public StyledString getStyledDisplayString() {
if (Boolean.TRUE.equals(item.getDeprecated())) {
return new StyledString(getDisplayString(), StyleUtil.DEPRECATE);
StyledString ss = Boolean.TRUE.equals(item.getDeprecated())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather keep the version isDeprecated() that we had on getStyledDisplayString(document, offset, boldStylerProvider)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sounds good

protected int currentOffset = -1;
protected @Nullable ITextViewer viewer;
private final IDocument document;
protected final IDocument document;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not following this part of the PR. Why does it need to be protected?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed... was a rogue change... :-\

Comment thread org.eclipse.lsp4e/META-INF/MANIFEST.MF Outdated
Bundle-Name: Language Server Protocol client for Eclipse IDE (Incubation)
Bundle-SymbolicName: org.eclipse.lsp4e;singleton:=true
Bundle-Version: 0.18.20.qualifier
Bundle-Version: 0.19.0.qualifier

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could not just be 0.18.21 following what we did so far?


if (infoControlCreator == null) {
/*
* FIXME: Take control creators (and link handling) out of JavadocHover,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been marked as RESOLVED WONTFIX, so probably it will never happen. Should we remove the FIXME and leave the link to the bug report?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove part of the comment

import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jdt.internal.codeassist.RelevanceConstants;
import org.eclipse.jdt.internal.ui.JavaPlugin;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mickaelistria , should we be avoiding importing internal classes from the JDT or is this something that is not an issue if you are part of the SimRel?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, better avoiding it (when possible)

import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jdt.internal.codeassist.RelevanceConstants;
import org.eclipse.jdt.internal.ui.JavaPlugin;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, better avoiding it (when possible)

*/
@Override
public @Nullable IInformationControlCreator getInformationControlCreator() {
Shell shell= JavaPlugin.getActiveWorkbenchShell();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That part can probably be inlined instead of referencing the internal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

*/
private @Nullable String getCSSStyles() {
if (fgCSSStyles == null) {
Bundle bundle= Platform.getBundle(JavaPlugin.getPluginId());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would better use FrameworkUtil.getBundle(IJavaEditorTextHover.class) (an API class related to the file we want)

}
fgCSSStyles= buffer.toString();
} catch (IOException ex) {
JavaPlugin.log(ex);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error happens in the current bundle, so let's not log it as it it were created by JavaPlugin. Let's log using the current bundle. If using recent enough platform ILog.get().error(ex.getMessage(), ex) should be a good substitute.

@BoykoAlex BoykoAlex mentioned this pull request Apr 4, 2025
@BoykoAlex

Copy link
Copy Markdown
Contributor Author

@rubenporras I have separated out label details, addressed your comments (Thank you very much for the comments by the way). Also cleaned up a few things. Lets see what else stands out to you :-)

@BoykoAlex BoykoAlex changed the title Rework JDT completions via LSP. Support completion label details Rework JDT completions via LSP Apr 4, 2025
@mickaelistria
mickaelistria merged commit 366d962 into eclipse-lsp4e:main Apr 4, 2025
rubenporras pushed a commit that referenced this pull request Apr 7, 2025
Support `CompletionItem` `LabelDetails` object

Separated from #1238
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants