Skip to content
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

Add VSCode marketplace client handler #32

Closed
wants to merge 2 commits into from
Closed

Add VSCode marketplace client handler #32

wants to merge 2 commits into from

Conversation

jfcherng
Copy link
Contributor

@jfcherng jfcherng commented Oct 18, 2020

There are some LSP servers, which are only available either on VSCode's marketplace or as .vsix files.

This PR proposes a dedicated handler, which should simplify LSP-* plugin codes for them.

It

  • downloads the extension from the marketplace with given extension itemName and version
  • unzips the downloaded .vsix file
  • checks node executable availability if necessary

An example use for https://marketplace.visualstudio.com/items?itemName=Nightrains.robloxlsp

import os
import sublime

from LSP.plugin.core.typing import List
from lsp_utils import VscodeMarketplaceClientHandler


def get_server_bin_path(platform: str = sublime.platform()) -> str:
    """
    @brief Get the LSP server binary path.
    @param platform The platform ("osx", "linux" or "windows")
    @return The LSP server binary path.
    """

    os_bin = {
        "linux": ["Linux", "lua-language-server"],
        "osx": ["macOS", "lua-language-server"],
        "windows": ["Windows", "lua-language-server.exe"],
    }

    return os.path.join("extension", "server", "bin", *(os_bin[platform]))


class LspRobloxPlugin(VscodeMarketplaceClientHandler):
    package_name = "LSP-Roblox"

    # @see https://marketplace.visualstudio.com/items?itemName=Nightrains.robloxlsp
    extension_item_name = "Nightrains.robloxlsp"
    extension_version = "0.11.5"
    server_binary_path = get_server_bin_path()
    execute_with_node = False

    @classmethod
    def get_binary_arguments(cls) -> List[str]:
        basename = "{}.sublime-settings".format(cls.package_name)
        settings = sublime.load_settings(basename)

        return [
            "-E",
            os.path.join(
                "${package_cache_path}",
                "extension",
                "server",
                settings.get("main_lua_file"),
            ),
        ]

@jfcherng jfcherng marked this pull request as ready for review October 18, 2020 06:42
@rwols
Copy link
Member

rwols commented Oct 18, 2020

Javascript files downloaded from that "marketplace" probably expect the node.js runtime to be a certain version, namely the one shipped with VSCode. How would you handle this?

@jfcherng
Copy link
Contributor Author

jfcherng commented Oct 18, 2020

Javascript files downloaded from that "marketplace" probably expect the node.js runtime to be a certain version, namely the one shipped with VSCode. How would you handle this?

what if something like

@classmethod
def minimum_node_version(cls) -> Tuple[int, int, int]:
return (8, 0, 0)
, such as

    @classmethod
    def satisfy_node_version(cls, version: Tuple[int, int, int]) -> bool:
		# `version` is a tuple of the found node version in the form of (major, minor, patch)

        # if the node version should >= 8.0.0 but < 14.0.0
        return (14, 0, 0) > version >= (8, 0, 0)

@rwols
Copy link
Member

rwols commented Oct 18, 2020

I was playing around with general prerequisites in this branch actually: sublimelsp/LSP@a78e958

@rwols
Copy link
Member

rwols commented Oct 18, 2020

While it's an interesting approach to add general routines for downloading things from the vscode marketplace, in the case of LSP-roblox I'm not totally convinced it's the most clean result. For instance, that vscode extension bundles binary files for all three platforms inside of the extension.

I made an LSP-lua repo where I actually separate out those three binaries into the three platforms, and also remove all unneeded files like debugger.lua and all beta Lua files: https://github.com/sublimelsp/LSP-lua

If you look at the releases page there, each (automated) release has zip assets for all three ST platforms (well, only x64 versions). So the binaries are placed in the package itself and there's no need to download files after the package is installed with package control at all.

There is also a person already waiting to release an LSP-roblox package: sublimelsp/repository#2

@jfcherng
Copy link
Contributor Author

jfcherng commented Oct 18, 2020

Agree on "if we can have a dedicated release for each platform, it's ideal."

A big bundle from the marketplace is for the sake of maintainer's laziness and easiness 😆


There is also a person already waiting to release an LSP-roblox package: sublimelsp/repository#2

Definitely good given the fact that I don't write Lua scripts.

@rchl
Copy link
Member

rchl commented Oct 18, 2020

I think I have nothing against the idea but there is an awful lot of duplication between existing and new handlers. I think it would make sense to extract common code into a common base.

@rchl
Copy link
Member

rchl commented Oct 18, 2020

Also, I would like to complete the move to a new server directory before introducing those new handlers.

@jfcherng
Copy link
Contributor Author

jfcherng commented Nov 9, 2020

Close this due to lack of public use case and... and I won't have much time for this recently :/

@jfcherng jfcherng closed this Nov 9, 2020
@rchl
Copy link
Member

rchl commented Nov 9, 2020

I'm not certain if it would be useful either and also wonder about the legality of doing that but I'm working on some refactorings in lsp_utils that will make it much easier to implement new handlers without duplication.

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.

3 participants