Skip to content

Support "Always Up" language servers - #289

Merged
mickaelistria merged 1 commit into
eclipse-lsp4e:masterfrom
BoykoAlex:always-up
Nov 18, 2022
Merged

mickaelistria merged 1 commit into
eclipse-lsp4e:masterfrom
BoykoAlex:always-up

Conversation

@BoykoAlex

Copy link
Copy Markdown
Contributor

Draft implementation of "alwaysUp" attribute for language server extension point.

@mickaelistria

Copy link
Copy Markdown
Contributor

@martinlippert added some time ago https://github.com/eclipse/lsp4e/blob/master/org.eclipse.lsp4e/schema/languageServer.exsd#L145 . Setting this lastDocumentDisconnectedTimeout to Integer.MAX_VALUE should achieve good enough results already, with an uptime of 68 years.

@martinlippert

Copy link
Copy Markdown
Contributor

I actually think that keeping the language server running for a longer time (like Integer.MAX_VALUE) is only one part of the question. I think the other part (when to startup the language server) also requires some discussion.

The PR from @BoykoAlex allows you to basically startup the language server at IDE startup time, independent of any project contents in your workspace. While I can see this could be useful, I think it would also be good to maybe have some kind of API on the extension that can decide when to start the language server, e.g.:

  • when the first content-type connected file is opened
  • when there are files from those content-types in the workspace
  • when there are specific (but random) files in the workspace
  • some custom logic

WDYT?

@mickaelistria

Copy link
Copy Markdown
Contributor

I think from LSP4E perspective, we could adopt the proposed idea as it's not too intrusive. Or maybe, just have LSP4E providing an org.eclipse.lsp4e.LSStartup extension factory that consumers could use in their IStartup with the syntax:

  <extension point="org.eclipse.ui.startup">
     <startup class="org.eclipse.lsp4e.LSStartup:org.eclipse.corrosion.rls"/>
  </extension>

?

About allowing multiple strategies, including not yet identified one, I believe it can become too custom to be worth being standardized in LSP4E. Consumers of LSP4E would IMO be more efficient at implementing whichever hook or listener they want by themselves and trigger the LS startup. Maybe we need a bit more API for it to be easy though.

@rubenporras

Copy link
Copy Markdown
Contributor

I also use https://github.com/eclipse/lsp4e/blob/master/org.eclipse.lsp4e/schema/languageServer.exsd#L145 as a poor man solution, if there is an option to start the LS on startup or something more configurable, that would be a good addition.

The proposed extension point

would be just what we need if we combine with the Integer.MAX_VALUE to keep the server running, which we already use

@BoykoAlex

Copy link
Copy Markdown
Contributor Author

Reading the above, perhaps, all LSP4E needs is public LanguageServiceAccessor.startLanguageServer(String id) where id is the LS definition id from the extension point. The method would start the LS if not already started. The logic/conditions under which the LS to be started would go into a downstream LS plugin which could either start the LS at IDE start up (i.e. IStartup interface via the startup extension) or at some specials conditions met by the workspace projects (i.e. java project present with spring on the classpath).
How does this sound?

@mickaelistria

Copy link
Copy Markdown
Contributor

I imagine you can already achieve a startup in your code with a combination like

var definition = LanguageServerRegistry.getInstance().getDefinition(languageServerId);
var dummyFile = File.createTempFile("initLS", "someExtension");
var fileBufferManager = FileBuffersPlugin.getFileBufferManager();
var dummyDocument = fileBufferManager.getFileBufferManager().createEmptyDocument(new Path(dummyFile.getAbsolutePath()), LocationKind.LOCATION);
getInitializedLanguageServer(dummyDocument, definition, cap -> true) // actually starts the LS
   .thenRun(() -> {
      fileBufferManager.disconnect(dummyFile.getAbsolutePath(), LocationKind.LOCATION, null);
      dummyFile.delete();
   });

But a shorter API such as LanguageServiceAccessor.startLanguageServer(LanguageServerRegistry.getInstance().getDefinition(languageServerId)) would be welcome.

@BoykoAlex

Copy link
Copy Markdown
Contributor Author

@mickaelistria I'd stop at your proposal: LanguageServiceAccessor.startLanguageServer(LanguageServerRegistry.getInstance().getDefinition(languageServerId))

Let us work out things on our side and if this is all we need (which is very likely) then I'll change this PR accordingly and prepare it to be merged.

@mickaelistria mickaelistria 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.

Looks good. Please mark as "Ready for review" if this is ready to be merged on your end as well.

startStopTimer();
} else {
stop();
if (!this.serverDefinition.alwaysUp) {

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.

We already can set the timeout to a extremely high number, which would do the same, so I think we do not need this. Having an org.eclipse.lsp4e.LSStartup extension factory as proposed by @mickaelistria looks enough to me. Otherwise we have flags with overlapping concerns, which I think we do not yet need.

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.

Switched to a solution where we just have the method for starting the language server

Comment thread org.eclipse.lsp4e/plugin.xml Outdated
</enabledWhen>
</reconciler>
</extension>
</extension>

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.

It would be good to remove this file form the commit.

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.

Corrected.

synchronized (startedServers) {
LanguageServerWrapper wrapper = startedServers.stream().filter(w -> w.serverDefinition == serverDefinition).findFirst().orElse(null);
if (wrapper == null) {
wrapper = new LanguageServerWrapper(serverDefinition, null);

@rubenporras rubenporras Nov 14, 2022 •

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 looks good to me and I would be happy to merge, but I was wondering if we could do better than orElse(null). Could we not just use new LanguageServerWrapper(serverDefinition, null) in the orElse() above and then just call startedServers.add(wrapper), the startedServers is a set so even if the wrapper is already in it, nothing bad should happen. If we want to avoid the add when the value was already present, we could use orElseGet().

What do you think about that?

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.

Sure, cleaning up as suggested above looks like a good idea

}
}

public static LanguageServerWrapper startLanguageServer(@NonNull LanguageServerDefinition serverDefinition) throws IOException {

@rubenporras rubenporras Nov 14, 2022 •

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.

add @NonNull to the return value?

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.

Sounds good

@mickaelistria

Copy link
Copy Markdown
Contributor

@BoykoAlex when it's ready to be merged, please click "Ready for review".

@BoykoAlex

Copy link
Copy Markdown
Contributor Author

@mickaelistria @rubenporras do you know what i can do with enabledWhen element under languageServer extension contentTypeMapping? I'd like to check if the resource being opened in the editor belongs to a Java project with spring boot on the classpath... Is there a way to get to the resource with propertyTesters under enabledWhen element? I looked at the context object which is being passed to the evaluation and seems like i might be able to get active IEditorInput from it... However, I'm curious how enabledWhen is being used now...

@rubenporras

Copy link
Copy Markdown
Contributor

Hi @BoykoAlex,

I do not know this API very well, but we have testers that override this method

  @Override
  public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
    Assert.isInstanceOf(receiver, IContainer.class, "The receiver must be an IContainer."); //$NON-NLS-1$
    IContainer container = (IContainer) receiver;
    IProject project = container.getProject();
    if (project.isOpen()) {
      ...
    } else {
      return false;
    }
  }

and then something like

            <enabledWhen>
               <iterate
                     operator="and">
                     <adapt type="org.eclipse.core.resources.IContainer">
                      <test
                            property="com.........myTester">
                      </test>
                     </adapt>
               </iterate>
            </enabledWhen>

does it bring you further?

@BoykoAlex

BoykoAlex commented Nov 17, 2022 •

Copy link
Copy Markdown
Contributor Author

@mickaelistria thank you - I'll give it a try... Was roaming yesterday through lsp4e code and after looking at https://github.com/eclipse/lsp4e/blob/dd39ca0db5e6abd3cb5f59a3e63cf6b2e1a20d46/org.eclipse.lsp4e/src/org/eclipse/lsp4e/enablement/EnablementTester.java#L61 I've decided that evaluation context is just instance of Object that is not useful at all, but i never tried any testers so let me try it out

@BoykoAlex
BoykoAlex marked this pull request as ready for review November 17, 2022 23:12
@BoykoAlex

Copy link
Copy Markdown
Contributor Author

Ready to merge this one. I'll move enabledWhen proposals into a separate PR if applicable

@BoykoAlex BoykoAlex changed the title [DO NOT MERGE] Support "Always Up" language servers Support "Always Up" language servers Nov 17, 2022
@rubenporras

Copy link
Copy Markdown
Contributor

@mickaelistria , ok to merge?

@mickaelistria

Copy link
Copy Markdown
Contributor

Yes, let's just ensure we have a green CI build before merging (the last build had some rare but random test failure, let's just verify it's not persistent)

@mickaelistria
mickaelistria merged commit 0c5cfd7 into eclipse-lsp4e:master Nov 18, 2022
@mickaelistria

Copy link
Copy Markdown
Contributor

Thanks!

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