# Configuring Julia formatter and linter with nvim-lspconfig for neovim

**URL:** https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746
**Category:** Tooling
**Tags:** staticlint, neovim, formatting
**Created:** [May 26, 2024, 7:42am UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746 "2024-05-26T07:42:41Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![mostafatouny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mostafatouny/32/223777_2.png) [@mostafatouny](https://discourse.julialang.org/u/mostafatouny)
#### Post date: [May 26, 2024, 7:42am UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/1 "2024-05-26T07:42:41Z")

</div>

Hello,

For Neovim, I have successfully integrated LanguageServer.jl through _lspconfig_ as instructed [here](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#julials). _Auto-completion_ and _hover documentation_ worked.

> **screenshot**
>
> ![Screenshot_2024-05-26_10-55-57](https://global.discourse-cdn.com/julialang/original/3X/5/a/5acc543cd2438530126f030043868003b61b2ed6.jpeg)

I want to integrate JuliaFormatter.jl and StaticLint.jl which are installed in the project located in `~/.julia/environment/nvim-lspconfig` but I can’t figure how to do it.

> **nvim-lspconfig.lua**
>
> ```julia
> -- (1) install lsp, formatter, and linter with Mason
> -- --
> 
> -- import lsp keymaps
> local on_attach = require("config.keymaps_lspsaga").on_attach
> 
> -- import local UTF-8 icons
> local diagnostic_signs = require("util.icons").diagnostic_signs
> 
> local config = function()
> require("neoconf").setup({})
> -- nvim-cmp package
> local capabilities = require('cmp_nvim_lsp').default_capabilities()
> 
> -- lspconfig package
> local lspconfig = require("lspconfig")
> 
> -- set diagnostic icons
> for type, icon in pairs(diagnostic_signs) do
> local hl = "DiagnosticSign" .. type
> vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
> end
> 
> -- (2) LSP Setup
> -- -- --
> 
> -- lua
> lspconfig.lua_ls.setup({
> -- attach nvim-cmp
> capabilities = capabilities,
> 
> -- set lsp keymaps
> on_attach = on_attach,
> 
> settings = {
> Lua = {
> -- make the language server recognize "vim" global
> diagnostics = {
> globals = { "nvim" }, -- was vim
> },
> workspace = {
> -- make language server aware of runtime files
> library = {
> [vim.fn.expand("$VIMRUNTIME/lua")] = true,
> [vim.fn.stdpath("config") .. "/lua"] = true,
> },
> },
> },
> },
> })
> 
> -- python
> lspconfig.pyright.setup({
> -- attach nvim-cmp
> capabilities = capabilities,
> 
> -- set lsp keymaps
> on_attach = on_attach,
> 
> -- features
> settings = {
> pyright = {
> disableOrganizeImports = false,
> analysis = {
> useLibraryCodeForTypes = true,
> autoSearchPaths = true,
> diagnosticMode = "workspace",
> autoImportCompletions = true,
> },
> },
> },
> })
> 
> -- haskell
> lspconfig.hls.setup({
> -- attach nvim-cmp
> capabilities = capabilities,
> 
> -- set lsp keymaps
> on_attach = on_attach,
> 
> -- settings for haskell
> settings = {
> haskell = {
> formattingProvider = "fourmolu", -- using fourmolu
> },
> },
> })
> 
> -- julia
> -- uses project ~/.julia/environments/nvim-lspconfig
> -- requires only: Pkg add LanguageServer
> -- doc: https://github.com/neovim/nvim-lspconfig/blob/b972e7154bc94ab4ecdbb38c8edbccac36f83996/doc/server_configurations.md#julials
> -- auto-completion worked
> lspconfig.julials.setup({})
> 
> -- (3) linter and formatter objects
> -- -- --
> 
> -- lua
> local luacheck = require("efmls-configs.linters.luacheck") -- linter
> local stylua = require("efmls-configs.formatters.stylua") -- formatter
> 
> -- python
> local flake8 = require("efmls-configs.linters.flake8") -- linter
> local black = require("efmls-configs.formatters.black") -- formatter
> 
> -- haskell
> local hlint = { -- linter
> lintCommand = "hlint --stdin",
> lintStdin = true,
> lintFormats = {"%f:%l:%c: %m"},
> }
> local fourmolu = { -- formatter
> formatCommand = "fourmolu --stdin-input-file ${INPUT}",
> formatStdin = true,
> }
> 
> -- (4) efm server
> -- -- --
> lspconfig.efm.setup({
> filetypes = {
> -- lua
> "lua",
> 
> -- python
> "python",
> 
> -- haskell
> "haskell",
> },
> init_options = {
> documentFormatting = true,
> documentRangeFormatting = true,
> hover = true,
> documentSymbol = true,
> codeAction = true,
> completion = true,
> },
> settings = {
> languages = {
> -- lua
> lua = { luacheck, stylua },
> 
> -- python
> python = { flake8, black },
> 
> -- haskell
> haskell = { hlint, fourmolu },
> },
> },
> })
> end
> 
> return {
> "neovim/nvim-lspconfig",
> config = config,
> lazy = false,
> dependencies = {
> "windwp/nvim-autopairs",
> "williamboman/mason.nvim",
> "creativenull/efmls-configs-nvim",
> },
> }
> 
> ```

---

<div class="post-metadata">

### Author: ![uncomfyhalomacro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uncomfyhalomacro/32/202833_2.png) [@uncomfyhalomacro](https://discourse.julialang.org/u/uncomfyhalomacro)
#### Post date: [May 28, 2024, 3:49pm UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/2 "2024-05-28T15:49:45Z")

</div>

> **[Home](https://github.com/julia-vscode/LanguageServer.jl/wiki)**
>
> An implementation of the Microsoft Language Server Protocol for the Julia language. - julia-vscode/LanguageServer.jl

You might want to check the wiki.

---

<div class="post-metadata">

### Author: ![mostafatouny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mostafatouny/32/223777_2.png) [@mostafatouny](https://discourse.julialang.org/u/mostafatouny)
#### Post date: [May 28, 2024, 4:27pm UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/3 "2024-05-28T16:27:14Z")

</div>

Thanks. I checked [nvim-cmp and nvim-lspconfig](https://github.com/julia-vscode/LanguageServer.jl/wiki/Vim-and-Neovim#using-nvim-cmp-and-nvim-lspconfig) section but it does not seem to contain JuliaFormatter.jl or StaticLint.jl

Do I need to use alternative lsp plugins?

---

<div class="post-metadata">

### Author: ![uncomfyhalomacro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uncomfyhalomacro/32/202833_2.png) [@uncomfyhalomacro](https://discourse.julialang.org/u/uncomfyhalomacro)
#### Post date: [May 28, 2024, 11:13pm UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/4 "2024-05-28T23:13:30Z")

</div>

No you dont. LanguageServer.jl comes with StaticLint and JuliaFormatter. There is already a format function from nvim-lspconfig. You really have to check out other ppl configs like mine. I binded mine to Space + L + F to format.

---

<div class="post-metadata">

### Author: ![uncomfyhalomacro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uncomfyhalomacro/32/202833_2.png) [@uncomfyhalomacro](https://discourse.julialang.org/u/uncomfyhalomacro)
#### Post date: [May 28, 2024, 11:49pm UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/5 "2024-05-28T23:49:15Z")

</div>

I am not sure what part of the documentation or wiki that are missing tbh. But nvim-lspconfig will use whatever formatter has from the Language Server implementation of the language if it does exist. Julia’s LanguageServer.jl uses JuliaFormatter.jl for example. You can see it in action here

---

<div class="post-metadata">

### Author: ![mostafatouny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mostafatouny/32/223777_2.png) [@mostafatouny](https://discourse.julialang.org/u/mostafatouny)
#### Post date: [May 30, 2024, 5:50am UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/6 "2024-05-30T05:50:42Z")

</div>

I started to inspect and tinker with your configurations [here](https://codeberg.org/uncomfyhalomacro/erudite.nvim).

For the first step of installation, I installed LanguageServer.jl and PackageCompiler.jl in `nvim-lspconfig`. Then I faced a weird error:

 ![create_sysimage](https://global.discourse-cdn.com/julialang/original/3X/b/c/bc966b6e7f7bd7362d6e5d07d60cd5820e0b6a55.jpeg)

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [May 30, 2024, 7:17am UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/7 "2024-05-30T07:17:19Z")

</div>

You have a rogue `'` at the end of the line there.

---

<div class="post-metadata">

### Author: ![mostafatouny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mostafatouny/32/223777_2.png) [@mostafatouny](https://discourse.julialang.org/u/mostafatouny)
#### Post date: [May 30, 2024, 2:28pm UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/8 "2024-05-30T14:28:33Z")

</div>

You are right. Sorry for the bad question. I should be more careful.

---

<div class="post-metadata">

### Author: ![mostafatouny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mostafatouny/32/223777_2.png) [@mostafatouny](https://discourse.julialang.org/u/mostafatouny)
#### Post date: [May 30, 2024, 3:27pm UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/9 "2024-05-30T15:27:29Z")

</div>

After successfully compiling packages in @nvim-lspconfig, I couldn’t get Julia’s LSP running through your configurations. Even autocompletion does not work.

> **LspLog**
>
> ![Screenshot_2024-05-30_18-14-28](https://global.discourse-cdn.com/julialang/original/3X/b/2/b21f5a7b5a5aa1306d60e865cab17d8152ba5341.jpeg)
> 
> ![Screenshot_2024-05-30_18-13-32](https://global.discourse-cdn.com/julialang/original/3X/0/b/0b6e743780bfdb9d04dffda0bf921b73941964c6.jpeg)

> **LspInfo**
>
> ![Screenshot_2024-05-30_18-20-32](https://global.discourse-cdn.com/julialang/original/3X/5/1/51330603a6f2ef76d333ebd1cd1db31641dedea8.jpeg)

There is a minimal configuration [here](https://github.com/julia-vscode/LanguageServer.jl/wiki/Vim-and-Neovim#neovim-built-in-lsp) which uses `nvim-cmp` and `nvim-lspconfig` but I don’t feel you would recommend it.

What would be the minimal configuration you do recommend to test?

---

<div class="post-metadata">

### Author: ![uncomfyhalomacro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uncomfyhalomacro/32/202833_2.png) [@uncomfyhalomacro](https://discourse.julialang.org/u/uncomfyhalomacro)
#### Post date: [June 1, 2024, 11:51pm UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/10 "2024-06-01T23:51:48Z")

</div>

tbh i am not sure how yours doesn’t work when some of my friends use my config… and i see that it really ran from the logs. the question is, how much did you tinker that caused that error like if you touched the custom command i made. if not, it might be something else.

and just showing logs without what youre typing doesn’t really give much info.

EDIT: i will try a clean install by wiping out the config cache of my nvim lsp and try installing.

---

<div class="post-metadata">

### Author: ![uncomfyhalomacro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uncomfyhalomacro/32/202833_2.png) [@uncomfyhalomacro](https://discourse.julialang.org/u/uncomfyhalomacro)
#### Post date: [June 2, 2024, 1:37am UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/11 "2024-06-02T01:37:46Z")

</div>

Yep. it just works. Both project specific and global environment runs julia lsp just fine.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/9/d96af93875110fb1794b9613075b237422363cff.png)

I also made sure that this works even on a container instance of julia e.g. distrobox on this line [erudite.nvim/lua/lsp.lua at af692926e7cd8936f0acf25b59c0a4dd8dfaa83f - uncomfyhalomacro/erudite.nvim - Codeberg.org](https://codeberg.org/uncomfyhalomacro/erudite.nvim/src/commit/af692926e7cd8936f0acf25b59c0a4dd8dfaa83f/lua/lsp.lua#L159)

And this is the variable script path being used

- Initialising the variable: [erudite.nvim/lua/lsp.lua at af692926e7cd8936f0acf25b59c0a4dd8dfaa83f - uncomfyhalomacro/erudite.nvim - Codeberg.org](https://codeberg.org/uncomfyhalomacro/erudite.nvim/src/commit/af692926e7cd8936f0acf25b59c0a4dd8dfaa83f/lua/lsp.lua#L2-L5)
- Using the variable [erudite.nvim/lua/lsp.lua at af692926e7cd8936f0acf25b59c0a4dd8dfaa83f - uncomfyhalomacro/erudite.nvim - Codeberg.org](https://codeberg.org/uncomfyhalomacro/erudite.nvim/src/commit/af692926e7cd8936f0acf25b59c0a4dd8dfaa83f/lua/lsp.lua#L164)

This ensures it points to my custom script.

---

<div class="post-metadata">

### Author: ![uncomfyhalomacro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uncomfyhalomacro/32/202833_2.png) [@uncomfyhalomacro](https://discourse.julialang.org/u/uncomfyhalomacro)
#### Post date: [June 2, 2024, 1:42am UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/12 "2024-06-02T01:42:08Z")

</div>

There are possibilities why yours didn’t work.

- You have conflicting configurations.
- You tinkered the config but didn’t know what you were doing.
- You forgot to install some prerequisites before bootstrapping the configuration, aka “running nvim the first time”.

If one or more of these are happening, I am pretty sure you just need to read more documentation and learn about the Neovim editor. Jumping over to someone’s config without Lua/Vimscript knowledge and just copy-pasting is going to end up you being frustrated.

Otherwise, just use VSCode. It’s a decent editor. No more fusses about learning the config language when it’s just JSON.

---

<div class="post-metadata">

### Author: ![mostafatouny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mostafatouny/32/223777_2.png) [@mostafatouny](https://discourse.julialang.org/u/mostafatouny)
#### Post date: [June 3, 2024, 5:00pm UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/13 "2024-06-03T17:00:31Z")

</div>

Thank you for your generous time.

I re-pulled your updated repo without any modifications. I got these two errors once I run `nvim tem.jl`:

> **First Error**
>
> ![Screenshot_2024-06-03_19-49-33](https://global.discourse-cdn.com/julialang/original/3X/9/f/9ff323d95eb2a1dec73549bc70f2e2b531e4e7d8.jpeg)

> **Second Error**
>
> ![Screenshot_2024-06-03_19-50-37](https://global.discourse-cdn.com/julialang/original/3X/a/f/afae370edea8294742876fb9c310871ac6bbd0d6.jpeg)

I did not install `rust-analyzer`, `cargo`, `yarn`, or `tmux`.

Now you are free to either:

- Continue troubleshooting with me, or
- Point me to resources related to foundations of neovim and language servers.

I shall flag the thread as solved if you selected the latter.

Thanks again.

---

<div class="post-metadata">

### Author: ![uncomfyhalomacro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uncomfyhalomacro/32/202833_2.png) [@uncomfyhalomacro](https://discourse.julialang.org/u/uncomfyhalomacro)
#### Post date: [June 6, 2024, 12:07am UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/14 "2024-06-06T00:07:40Z")

</div>

There is one thing I noticed about this. Please install the pre-requisites. This is a personal config so much has to be done before doing anything.

One thing you must do are

- delete any rust-specific plugins at `lua/plugins.lua`
- delete the keymaps folder in lua folder.
- delete whichkey.nvim at `lua/plugins.lua`.
- you can leave `lua/lsp.lua` alone.
- delete `require("keymaps")` at `init.lua`.

but if this is too difficult for you, i can provide a very minimal config with just lazy.nvim and nvim-lspconfig installed with just julia as the language server.

---

<div class="post-metadata">

### Author: ![uncomfyhalomacro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uncomfyhalomacro/32/202833_2.png) [@uncomfyhalomacro](https://discourse.julialang.org/u/uncomfyhalomacro)
#### Post date: [June 6, 2024, 3:02am UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/15 "2024-06-06T03:02:08Z")

</div>

> [@mostafatouny](#):
>
> - Continue troubleshooting with me, or
> - Point me to resources related to foundations of neovim and language servers.

There are a lot of guides. You don’t need me. It’s something you need to make time to get used to or use existing configs from community like AstroNvim or [LazyVim](https://www.lazyvim.org/).

I have a smaller config just for you and feel free to read over it and copy over what’s necessary.

Smaller config here - [https://forgejo.uncomfyhalomacro.pl/uncomfyhalomacro/julia.nvim](https://forgejo.uncomfyhalomacro.pl/uncomfyhalomacro/julia.nvim)

---

<div class="post-metadata">

### Author: ![mostafatouny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mostafatouny/32/223777_2.png) [@mostafatouny](https://discourse.julialang.org/u/mostafatouny)
#### Post date: [June 6, 2024, 5:21am UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/16 "2024-06-06T05:21:23Z")

</div>

You are doing an incredible effort. Thank you so much.

For your new minimal configuration:

**Build**. I used `build = "julia --project=@nvim-lspconfig --startup-file=no --history-file=no"` and manually configured `nvim-lspconfig` project as instructed in your [erudite repo](https://codeberg.org/uncomfyhalomacro/erudite.nvim). The original `build` line did not work with me.

**lualine**. I get this error from `lualine`

> **lualine**
>
> ![Screenshot_2024-06-06_08-00-43](https://global.discourse-cdn.com/julialang/original/3X/6/c/6c70636ba0b0948052f941dddc94056a5eb0074c.png)

Removing `lualine` plugin caused error in the LSP, So I just ignored the error.

**LSP & Auto-cmp.** auto-completion and LSP successfully worked.

> **LSP & CMP**
>
> ![Screenshot_2024-06-06_07-54-37](https://global.discourse-cdn.com/julialang/original/3X/6/7/6777dec282c50a0d311dafc0e65ffba5c576636e.png)  
> ![Screenshot_2024-06-06_07-47-10](https://global.discourse-cdn.com/julialang/original/3X/1/5/15ea9efb6c6c3a222408d866a5886a0c5770d4fa.png)

**Lspsaga.** I had to install `Lspsaga` plugin in order to see diagnostics.

> **Lspsaga**
>
> ![Screenshot_2024-06-06_07-57-01](https://global.discourse-cdn.com/julialang/original/3X/3/c/3c4232af7c505a48ae6b6241f12992a695e11da1.png)

I still need to figure how to show diagnostics in-line rather than calling `Lspsaga show_buf_diagnostics`.

**Resources.** Spoon-feeding beyond this stage seems unhealthy. Would you recommend resources relevant to foundations of `language-servers`, and how `neovim` interacts with them?

**Wiki.** I suggest you minimize your configurations, removing `keymaps`, `neo-tree`, `lualine`, `colourscheme`, and `global settings`. Adding `latex-cmp` is reasonable. Then we send Julia’s wiki moderators to update [Tools](https://julialang.org/contribute/) section. The goal is not to run your configuration on my machine, but paving the way for the community to use neovim, so that anyone can learn and configure by herself. I am happy to assist.

Let me know your thoughts before I flag this thread as solved.

Thank you again. You are a wonderful friend.

---

<div class="post-metadata">

### Author: ![uncomfyhalomacro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uncomfyhalomacro/32/202833_2.png) [@uncomfyhalomacro](https://discourse.julialang.org/u/uncomfyhalomacro)
#### Post date: [June 6, 2024, 7:52am UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/17 "2024-06-06T07:52:17Z")

</div>

i think you have to exit neovim after the bootstrap and enter neovim again. that’s what is causing the error i believe

---

<div class="post-metadata">

### Author: ![uncomfyhalomacro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uncomfyhalomacro/32/202833_2.png) [@uncomfyhalomacro](https://discourse.julialang.org/u/uncomfyhalomacro)
#### Post date: [June 6, 2024, 7:56am UTC](https://discourse.julialang.org/t/configuring-julia-formatter-and-linter-with-nvim-lspconfig-for-neovim/114746/18 "2024-06-06T07:56:42Z")

</div>

> [@mostafatouny](#):
>
> **Wiki.** I suggest you minimize your configurations, removing `keymaps`, `neo-tree`, `lualine`, `colourscheme`, and `global settings`. Adding `latex-cmp` is reasonable. Then we send Julia’s wiki moderators to update [Tools](https://julialang.org/contribute/) section. The goal is not to run your configuration on my machine, but paving the way for the community to use neovim, so that anyone can learn and configure by herself. I am happy to assist.

I mean it should be possible. I just added those just to give you a feel of what it’s like adding a theme and a colorscheme. users can just use the built-in Netrw with `:Ntree` 🙂
