-
Notifications
You must be signed in to change notification settings - Fork 22
fix: Download LSP bundle with nodejs runtime #26
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
Changes from all commits
e9b8434
f2a9884
8d09142
b3048cf
d89fbb8
5e6ed97
a8fc011
017aad1
780d225
14cda1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package org.jboss.tools.intellij.analytics; | ||
|
|
||
| import com.intellij.openapi.components.PersistentStateComponent; | ||
| import com.intellij.openapi.components.RoamingType; | ||
| import com.intellij.openapi.components.State; | ||
| import com.intellij.openapi.components.Service; | ||
| import com.intellij.openapi.components.Storage; | ||
| import com.intellij.util.xmlb.XmlSerializerUtil; | ||
|
|
||
| @Service | ||
| @State( | ||
| name = "AnalyticsPersistentSettings", | ||
| storages = { | ||
| @Storage(file = "analytics.settings.xml", roamingType = RoamingType.DISABLED) | ||
| }) | ||
| public final class AnalyticsPersistentSettings implements PersistentStateComponent<AnalyticsPersistentSettings> { | ||
|
|
||
| private String lspVersion; | ||
|
|
||
| @Override | ||
| public AnalyticsPersistentSettings getState() { | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public void loadState(AnalyticsPersistentSettings state) { | ||
| XmlSerializerUtil.copyBean(state, this); | ||
| } | ||
|
|
||
| public void setLSPVersion(final String version) { | ||
| this.lspVersion = version; | ||
| } | ||
|
|
||
| public String getLSPVersion() { | ||
| return this.lspVersion; | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package org.jboss.tools.intellij.analytics; | ||
|
|
||
| import org.kohsuke.github.GitHub; | ||
| import org.kohsuke.github.GHAsset; | ||
| import org.kohsuke.github.GHRepository; | ||
| import org.kohsuke.github.GHRelease; | ||
| import java.io.IOException; | ||
|
|
||
| public class GHReleaseDownloader { | ||
| private final GHRepository repo; | ||
|
|
||
| public GHReleaseDownloader(final String repository) throws IOException { | ||
| final GitHub github = GitHub.connectAnonymously(); | ||
| this.repo = github.getRepository(repository); | ||
| } | ||
|
|
||
| public String getLatestRelease() throws IOException { | ||
| return this.repo.getLatestRelease().getTagName(); | ||
| } | ||
|
|
||
| public String getDownloadUri(final String releaseLabel, final String fileLabel) throws IOException { | ||
| final GHRelease release = this.repo.getReleaseByTagName(releaseLabel); | ||
| final GHAsset asset = release.listAssets() | ||
| .toList() | ||
| .stream() | ||
| .filter(a -> a.getLabel().equals(fileLabel)) | ||
| .findFirst() | ||
| .orElseThrow(() -> new IOException(fileLabel + ": unable to download")); | ||
| return asset.getBrowserDownloadUrl(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| package org.jboss.tools.intellij.analytics; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
|
|
||
| import com.intellij.ide.plugins.IdeaPluginDescriptor; | ||
| import com.intellij.ide.plugins.PluginManager; | ||
| import com.intellij.openapi.application.ApplicationManager; | ||
| import com.intellij.openapi.components.Service; | ||
| import com.intellij.openapi.components.ServiceManager; | ||
| import com.intellij.openapi.diagnostic.Logger; | ||
| import com.intellij.openapi.extensions.PluginId; | ||
| import com.intellij.openapi.progress.BackgroundTaskQueue; | ||
| import com.intellij.openapi.progress.ProgressIndicator; | ||
| import com.intellij.openapi.progress.Task; | ||
| import com.intellij.openapi.project.Project; | ||
| import com.intellij.util.io.HttpRequests; | ||
|
|
||
| import org.wso2.lsp4intellij.IntellijLanguageClient; | ||
|
|
||
| @Service | ||
| public final class LSPBundle { | ||
| private final IdeaPluginDescriptor descriptor = PluginManager.getPlugin(PluginId.getId("org.jboss.tools.intellij.analytics")); | ||
| private final GHReleaseDownloader downloader; | ||
| private File cliFile; | ||
| private final BackgroundTaskQueue taskQueue; | ||
| private final Project project; | ||
|
|
||
| private static final Logger log = Logger.getInstance(LSPBundle.class); | ||
|
|
||
| static interface DownloadListener { | ||
| void downloadCompleted(final File path); | ||
| } | ||
|
|
||
| public LSPBundle(final Project project) { | ||
| this.project = project; | ||
| try { | ||
| this.downloader = new GHReleaseDownloader("fabric8-analytics/fabric8-analytics-lsp-server"); | ||
| } catch (IOException ex) { | ||
| throw new LSPBundleException(ex.toString()); | ||
| } | ||
| this.cliFile = new File(descriptor.getPath(), Platform.current.lspBundleName); | ||
| this.taskQueue = new BackgroundTaskQueue(project, "Analytics"); | ||
| } | ||
|
|
||
| public File getCliPath() { | ||
| return this.cliFile; | ||
| } | ||
|
|
||
| public void download(final LSPBundle.DownloadListener listener) { | ||
| log.debug("download lsp bundle"); | ||
| taskQueue.run(new Task.Backgroundable(this.project, "Analytics lsp download", true) { | ||
| @Override | ||
| public void run(final ProgressIndicator indicator) { | ||
| try { | ||
| log.info("downloading cli " + LSPBundle.this.cliFile); | ||
| downloadIfNeeded(indicator); | ||
| } catch(IOException ex) { | ||
| log.warn("failed to download cli " + LSPBundle.this.cliFile); | ||
| return; | ||
| } | ||
| ApplicationManager.getApplication().invokeAndWait(() -> { | ||
| listener.downloadCompleted(LSPBundle.this.cliFile); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private boolean isNewRelease(final String releaseLabel) { | ||
| final String currentVersion = ServiceManager.getService(AnalyticsPersistentSettings.class).getLSPVersion(); | ||
| log.info(String.format("lsp version current %s, latest %s", currentVersion, releaseLabel)); | ||
| return !releaseLabel.equals(currentVersion); | ||
| } | ||
|
|
||
| public void downloadIfNeeded(final ProgressIndicator indicator) throws IOException { | ||
| final String latestReleaseTag = this.downloader.getLatestRelease(); | ||
| if (!isNewRelease(latestReleaseTag) && cliFile.exists()) { | ||
| return; | ||
| } | ||
| final String devUrl = System.getenv("ANALYTICS_LSP_FILE_PATH"); | ||
| final String url = this.downloader.getDownloadUri(latestReleaseTag, Platform.current.lspBundleName); | ||
| final String actualUrl = devUrl != null ? devUrl : url; | ||
| log.info(String.format("url %s", url)); | ||
| HttpRequests | ||
| .request(actualUrl) | ||
| .productNameAsUserAgent() | ||
| .saveToFile(cliFile, indicator); | ||
|
|
||
| cliFile.setExecutable(true); | ||
| ServiceManager.getService(AnalyticsPersistentSettings.class).setLSPVersion(latestReleaseTag); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package org.jboss.tools.intellij.analytics; | ||
|
|
||
| public class LSPBundleException extends RuntimeException { | ||
| public LSPBundleException(String ex) { | ||
| super(ex); | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package org.jboss.tools.intellij.analytics; | ||
|
|
||
| import com.intellij.openapi.util.SystemInfo; | ||
|
|
||
| public class Platform { | ||
| public String lspBundleName; | ||
|
|
||
| private static final Platform WINDOWS = new Platform("analytics-lsp-win.exe"); | ||
| private static final Platform LINUX = new Platform("analytics-lsp-linux"); | ||
| private static final Platform MACOS = new Platform("analytics-lsp-macos"); | ||
|
|
||
| private Platform(String lspBundleName) { | ||
| this.lspBundleName = lspBundleName; | ||
| } | ||
|
|
||
| private static Platform detect() { | ||
| if (SystemInfo.isLinux) | ||
| return LINUX; | ||
| if (SystemInfo.isWindows) | ||
| return WINDOWS; | ||
| if (SystemInfo.isMac) | ||
| return MACOS; | ||
| throw new PlatformDetectionException(SystemInfo.OS_NAME + " is not supported"); | ||
| } | ||
|
|
||
| public static final Platform current = detect(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package org.jboss.tools.intellij.analytics; | ||
|
|
||
| public class PlatformDetectionException extends RuntimeException { | ||
| public PlatformDetectionException(String ex) { | ||
| super(ex); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package org.jboss.tools.intellij.analytics; | ||
|
|
||
| import java.io.File; | ||
| import com.intellij.openapi.application.ApplicationManager; | ||
| import com.intellij.openapi.project.Project; | ||
| import com.intellij.openapi.startup.StartupActivity; | ||
| import com.intellij.openapi.diagnostic.Logger; | ||
| import org.wso2.lsp4intellij.IntellijLanguageClient; | ||
|
|
||
| public final class PostStartupActivity implements StartupActivity { | ||
| private static final Logger log = Logger.getInstance(PostStartupActivity.class); | ||
|
|
||
| @Override | ||
| public void runActivity(Project project) { | ||
| if (ApplicationManager.getApplication().isUnitTestMode()) { | ||
| return; | ||
| } | ||
|
|
||
| final LSPBundle.DownloadListener fileDownloadListener = (final File cliFile) -> { | ||
| final String[] EXTENSIONS = {"xml", "json", "txt"}; | ||
| final String[] cmds = {cliFile.toString(), "--stdio"}; | ||
| for(String ext : EXTENSIONS) { | ||
| AnalyticsLanguageServerDefinition serverDefinition = new AnalyticsLanguageServerDefinition(ext, cmds); | ||
| IntellijLanguageClient.addServerDefinition(serverDefinition); | ||
| IntellijLanguageClient.addExtensionManager(ext, serverDefinition); | ||
| } | ||
| log.debug("lsp registration done {0}", cliFile); | ||
| }; | ||
|
|
||
| log.debug("runActivity called for analytics with project {0}", project); | ||
| project.getService(LSPBundle.class).download(fileDownloadListener); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,13 +93,10 @@ | |
| <externalAnnotator id="LSPAnnotator-xml" language="XML" implementationClass="org.wso2.lsp4intellij.contributors.annotator.LSPAnnotator"/> | ||
| <externalAnnotator id="LSPAnnotator-json" language="JSON" implementationClass="org.wso2.lsp4intellij.contributors.annotator.LSPAnnotator"/> | ||
| <externalAnnotator id="LSPAnnotator-txt" language="TEXT" implementationClass="org.wso2.lsp4intellij.contributors.annotator.LSPAnnotator"/> | ||
| <postStartupActivity implementation="org.jboss.tools.intellij.analytics.PostStartupActivity"/> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason for having it implemented as application component is that postStartupActivity is delayed and thus if you have opened documents when you open a project, the LSP may not be started.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works. Also intellij doc says application component is deprecated. https://plugins.jetbrains.com/docs/intellij/plugin-components.html
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes but deprecated does not mean removed. So my concern is that if the file is already opened then seems the LSP is started but I can't see the decorations on the file.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jeffmaury I see similar issue even without this change. Can you just try adding a dummy line in the manifest to see whether it could decorate? it is a bug for sure, just want to check.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure to understand. If I comment this line out, then LSP won't be started at all. So If this is like before then we're good. |
||
| </extensions> | ||
|
|
||
| <application-components> | ||
| <component> | ||
| <interface-class>org.jboss.tools.intellij.analytics.AnalyticsPreloadActivity</interface-class> | ||
| <implementation-class>org.jboss.tools.intellij.analytics.AnalyticsPreloadActivity</implementation-class> | ||
| </component> | ||
| <component> | ||
| <implementation-class>org.wso2.lsp4intellij.IntellijLanguageClient</implementation-class> | ||
| </component> | ||
|
|
||
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.
The download plugin must be removed as well