Completion using arbitrary langauge servers in Java text blocks#1536
Completion using arbitrary langauge servers in Java text blocks#1536danthe1st wants to merge 1 commit into
Conversation
| private ICompletionProposal[] asJavaProposals(CompletableFuture<ICompletionProposal[]> future, ContentAssistInvocationContext context) | ||
| throws InterruptedException, ExecutionException, TimeoutException { | ||
| private ICompletionProposal[] asJavaProposals(CompletableFuture<ICompletionProposal[]> future, | ||
| ContentAssistInvocationContext context) throws InterruptedException, ExecutionException, TimeoutException { |
|
I think this would indeed be a very nice feature to have. How to do identify the type of language in the text block? The code creates a doc with |
|
I think this would be a nice addition. Regarding content recognition: // language=HTML
String html = "<body><h1>hi</h1></body>"; |
That is one of the main unanswered questions that I mentioned in the PR and that I'd like to get feedback on. I guess that it would be inferred from the source code in some way and ideally, that could be configured by both users (via a preference screen) and plugins which may have more information on that (e.g. plugins may know methods that expect |
I guess it might be useful to define a (configurable) regex for comments right before text blocks containing one group for the language? |
|
I don't really have a perfect solution in mind, but I usually don't like those approaches very much that require the developers to add things to the source code just to make the tooling happy (or working). |
I think we can still provide default values (i.e. have a configuration that's somewhat compatible with IntelliJ's approach) where applicable. |
What exactly do you have in mind here? Not sure I understand the "provide default values". Can you elaborate on that? |
My idea is maybe something like the following:
I guess it might make sense to start with the first one or two and others can be added later if someone is interested/has a good idea on how to do that. |
|
It would be useful to extract the exact strategy that identifies the language into a distinct component and open that up for extensions. The use case that I have in mind here is: In the Spring Tools, we know precisely for example when a SQL statement is used in a My guess is that other tools would also be able to identify those languages, since they are usually not totally random and can be inferred from the wider context. In our case it is the Spring Data specific |
233aca5 to
a584177
Compare
|
I updated the PR with some code that uses |
I think it would be nice if we could use language servers from inside Java text blocks.
To demonstrate it, I implemented a prototype that can provide completions in the following way:
With the HTML language server from WildWebDeveloper, this looks like this:
Screencast_20260516_151757.webm
When I say logical content, I mean the parsed

Stringthat Java will know about (which I can get from JDT) which is also shown when hovering over it:Specifically, I have the following questions:
TextBlockSourceContentMapperfor converting positions within the Java code to positions within the logical text block content. Does anyone a better approach (e.g. getting it from JDT in some way) to this?Stringis directly assigned to a variable/used as a parameter namedhtml, it may want to treat it like an.htmlfile)@Language("sql")or@Sqlthat are somehow associated with the string (e.g. by annotating parameters or variables)Stringis passed to certain "known" method (e.g.Connection#prepareStatement), the language server could be inferred.Limitations
This requires the
org.eclipse.lsp4e.resourceFallback.enabledpreference being set totrue(at least for now).Note that this is everything but complete. I am creating a draft pull request to have a prototype as a base for discussions. For example, I hardcoded it using
htmlfor now.