From 02ba678077f3f8c9ee732f565cbc4bf7ac33abb1 Mon Sep 17 00:00:00 2001 From: Joel Schutz Date: Sat, 11 Feb 2023 23:39:39 -0300 Subject: [PATCH] Adds experimental Go spec --- .../jupyter_lsp/jupyter_lsp/specs/__init__.py | 2 + .../jupyter_lsp/jupyter_lsp/specs/gopls.py | 38 +++++++++++++++++++ python_packages/jupyter_lsp/setup.cfg | 1 + 3 files changed, 41 insertions(+) create mode 100644 python_packages/jupyter_lsp/jupyter_lsp/specs/gopls.py diff --git a/python_packages/jupyter_lsp/jupyter_lsp/specs/__init__.py b/python_packages/jupyter_lsp/jupyter_lsp/specs/__init__.py index edd15f613..ed97e319c 100644 --- a/python_packages/jupyter_lsp/jupyter_lsp/specs/__init__.py +++ b/python_packages/jupyter_lsp/jupyter_lsp/specs/__init__.py @@ -11,6 +11,7 @@ from .pyright import PyrightLanguageServer from .python_lsp_server import PythonLSPServer from .r_languageserver import RLanguageServer +from .gopls import GoLanguageServer from .sql_language_server import SQLLanguageServer from .texlab import Texlab from .typescript_language_server import TypescriptLanguageServer @@ -32,6 +33,7 @@ py_lsp_server = PythonLSPServer() pyright = PyrightLanguageServer() r = RLanguageServer() +go = GoLanguageServer() tex = Texlab() ts_old = JavascriptTypescriptLanguageServer() ts = TypescriptLanguageServer() diff --git a/python_packages/jupyter_lsp/jupyter_lsp/specs/gopls.py b/python_packages/jupyter_lsp/jupyter_lsp/specs/gopls.py new file mode 100644 index 000000000..1c2f3a78f --- /dev/null +++ b/python_packages/jupyter_lsp/jupyter_lsp/specs/gopls.py @@ -0,0 +1,38 @@ +from .utils import ShellSpec +from typing import Union + +TROUBLESHOOT = """\ +You probably just need to install either *gopls* or the *jupyter-gopls* +just use the commands below. +""" + + +class GoLanguageServer(ShellSpec): + key = cmd = "gopls" + package = "jupyter_gopls" # Package with parser for golang + args = ["serve"] + is_installed_args = ["version"] + languages = ["go"] + + spec = dict( + display_name=key, + mime_types=["text/x-go", "text/go"], + urls=dict( + home="https://pkg.go.dev/golang.org/x/tools/gopls", + ), + # config_schema=load_config_schema(key), # TODO Find this options for this server + troubleshoot=TROUBLESHOOT, + shadow_file_ext=".go", # Not implemented yet, may be removed in future. See issue #872 + install=dict( + go="go get golang.org/x/tools/gopls@latest", # This may never change + pip="pip install {}".format(package), # This package is not published yet + ) + ) + + def solve(self) -> Union[str, None]: + # Check if python package is installed + pkg = __import__(self.package) + if not pkg: + return + return super().solve() + diff --git a/python_packages/jupyter_lsp/setup.cfg b/python_packages/jupyter_lsp/setup.cfg index f52cd4212..87e81f4bf 100644 --- a/python_packages/jupyter_lsp/setup.cfg +++ b/python_packages/jupyter_lsp/setup.cfg @@ -43,6 +43,7 @@ jupyter_lsp_spec_v1 = python-lsp-server = jupyter_lsp.specs:py_lsp_server pyright = jupyter_lsp.specs:pyright r-languageserver = jupyter_lsp.specs:r + go-language-server = jupyter_lsp.specs:go texlab = jupyter_lsp.specs:tex typescript-language-server = jupyter_lsp.specs:ts sql-language-server = jupyter_lsp.specs:sql