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

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

Open
marcoskichel opened this issue Dec 23, 2023 · 4 comments
Open

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

marcoskichel opened this issue Dec 23, 2023 · 4 comments

Comments

@marcoskichel
Copy link

marcoskichel commented Dec 23, 2023

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.

@marcoskichel marcoskichel changed the title Question: Is it possible to use this project outside VS Code? Question: Is it possible to use this project outside of VS Code? Dec 23, 2023
@pgrivachev
Copy link
Collaborator

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: #1194 (comment).

@marcoskichel
Copy link
Author

marcoskichel commented Dec 26, 2023

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
Copy link
Collaborator

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.

ref_sql.mp4

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

this.sendNotification('custom/updateQueryPreview', { uri, previewText, refReplacements });
and also send diagnostics
this.sendNotification('custom/updateQueryPreviewDiagnostics', { uri, diagnostics: compiledDiagnostics });

Other feature is dbt status. We send information about dbt configuration

this.sendNotification('WizardForDbtCore(TM)/status', statusNotification);
, we can install dbt packages, dbt adapters, update/install dbt.

@egh
Copy link

egh commented May 24, 2024

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)

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

No branches or pull requests

3 participants