fivetran / dbt-language-server

https://marketplace.visualstudio.com/items?itemName=Fivetran.dbt-language-server
MIT License
2 stars 0 forks source link

Question: Is it possible to use this project outside of VS Code? #1426

Open marcoskichel opened 11 months ago

marcoskichel commented 11 months ago

I'm currently using Neovim as my text editor and I would love to have a DBT language server integrated into my workflow.

I usually install language servers through a plugin called Mason, which is a package manager for LSPs and other tools, however this project is not listed as an option there.

In the current project's documentation section, the instructions are particular for VSCode users, so I wonder if there is any way to have the DBT language-server running "standalone" in my system, outside of VSCode.

Any help is truly appreciated.

pgrivachev commented 11 months ago

Hey @marcoskichel, we publish only extension for VS Code and standalone Language Server npm package at the moment. You might want to try using this npm package with Neovim. Here is the configuration that can help: https://github.com/fivetran/dbt-language-server/issues/1194#issuecomment-1813327126.

marcoskichel commented 11 months ago

I managed to get it working with this config:

local configs = require("lspconfig.configs")

configs.dbt = {
  default_config = {
    cmd = { "dbt-language-server", "--stdio" },
    root_dir = require("lspconfig.util").root_pattern("dbt_project.yml", "dbt_project.yaml"),
    filetypes = { "sql", "yml" },
  },
}

require("lspconfig").dbt.setup({
  init_options = {
    pythonInfo = {
      path = "/usr/bin/python",
    },
    lspMode = "dbtProject",
    enableSnowflakeSyntaxCheck = true,
  },
})

I can raise a PR with some descriptions once I am positive there are no loose ends if you like @pgrivachev. It seems to be already doing a good job though, I can get auto-completion for models and column names, "go to definition", and some static validation, which was mainly what I was looking for...

In any case, I wonder if there are any other capabilities a Neovim user might benefit from... I noticed that you have a "convert to model" feature that allows you to change a reference from a plain table to a model reference, right?

I don't have much knowledge about the protocol, but that one sounds like something "extra", right? I wonder if are there any other "extra" features you provide that I might use. Also, is there any documentation available about the available RPC methods? Especially the ones that are not part of the protocol, since the default config already handles these pretty well.

If you don't have docs or even inline docs, maybe can you point me to some code file that "exports" the methods or something like that?

pgrivachev commented 11 months ago

I can raise a PR with some descriptions once I am positive there are no loose ends if you like @pgrivachev

Sure it will be great if you write some instructions.

I noticed that you have a "convert to model" feature that allows you to change a reference from a plain table to a model reference, right?

Yes, we have it. It uses code action language server capability. And I checked that in helix it works.

https://github.com/fivetran/dbt-language-server/assets/3650304/a7b5b322-16fb-4e63-87cf-24c89474a898

If you don't have docs or even inline docs, maybe can you point me to some code file that "exports" the methods or something like that?

We have Query preview that shows preview of compiled models. On each model change we send preview text here https://github.com/fivetran/dbt-language-server/blob/f0d2b77055a5d095f98c0ce293be73a10e993cc3/server/src/NotificationSender.ts#L36 and also send diagnostics https://github.com/fivetran/dbt-language-server/blob/f0d2b77055a5d095f98c0ce293be73a10e993cc3/server/src/NotificationSender.ts#L9

Other feature is dbt status. We send information about dbt configuration https://github.com/fivetran/dbt-language-server/blob/f0d2b77055a5d095f98c0ce293be73a10e993cc3/server/src/NotificationSender.ts#L40, we can install dbt packages, dbt adapters, update/install dbt.

egh commented 6 months ago

This is working for me with emacs lsp-mode with the following config:

(defgroup lsp-dbt nil
  "LSP support for DBT."
  :link '(url-link "https://github.com/fivetran/dbt-language-server")
  :group 'lsp-mode)

(defcustom lsp-dbt-server-command '("dbt-language-server" "--stdio")
  "The dbt-language-server command."
  :group 'lsp-dbt
  :risky t
  :type 'list)

(add-to-list 'lsp-language-id-configuration
             '("/\\(dbt\\|queries\\|macros\\|dbt_modules\\)/.*\\.sql\\'" . "dbt"))

(lsp-register-client
 (make-lsp-client :new-connection (lsp-stdio-connection lsp-dbt-server-command)
                  :activation-fn (lsp-activate-on "dbt")
                  :language-id "sql"
                  :server-id 'dbtls
                  :initialization-options '(:pythonInfo (:path "python")
                                                       :lspMode "dbtProject"
                                                       :enableSnowflakeSyntaxCheck t
                                                       :disableLogger t)))

(lsp-consistency-check lsp-dbt)