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

fix(biome): find root when using biome.jsonc #4774

Merged
merged 1 commit into from
Jun 25, 2024

Conversation

redbmk
Copy link
Contributor

@redbmk redbmk commented May 13, 2024

Since biome supports either biome.json or biome.jsonc config files, we need to look for both when searching for the LSP project root. We can also look for a package.json or .git folder to use. This uses mostly the same logic as deno.


I added some documentation for the new option and explained the new logic. This is pretty much copied from the deno documentation (and code) with some minor tweaks. Probably could refactor to some shared code at some point, just not sure where to put it.

I also added a couple tests and made sure tests and linting pass locally.

This will have minor conflicts with #4763 and #4773 but I wanted to keep the commits fairly atomic and the conflicts will be quick to clean up.

@redbmk
Copy link
Contributor Author

redbmk commented Jun 21, 2024

Guessing adding biome.jsonc somehow broke the deno tests. Not really seeing why that is, but getting tests set up locally again to test out some theories.

Edit: yeah that ended up being it, though I'm not quite sure why. I just created a new biome folder for test files that so it doesn't mess with the files deno is expecting to be there.

@Spixmaster
Copy link
Contributor

Spixmaster commented Jun 21, 2024

The new commits still do not solve the issue for me. I get these errors.

 LSP Error Messages: 

(Errors for biome) 
Failed to find project root, language server won't start.

I do not understand since when I run the command biome check advertisement.ts --config-path ~/.config/biome/biome.json it executes successfully. In the terminal, there is no try to run a language server.

Why does Ale try to start the language server?

If I look here, that is the command I also run in my terminal which works.

vimcr:

" Basic (priority)
set t_Co=256

"" Needed for 'set termguicolors'
let &t_8b = "\<Esc>[48:2:%lu:%lu:%lum"
let &t_8f = "\<Esc>[38:2:%lu:%lu:%lum"

" Plugins (priority)
"" vim-airline
let g:airline_powerline_fonts = 1
let g:airline_theme = 'molokai'

"" vim-ale
let g:ale_fix_on_save = 1
let g:ale_fixers =
            \{
            \    '*': ['remove_trailing_lines', 'trim_whitespace'],
            \    'bib': ['bibclean', 'remove_trailing_lines', 'trim_whitespace'],
            \    'cpp': ['clang-format', 'remove_trailing_lines', 'trim_whitespace'],
            \    'cmake': ['cmakeformat', 'remove_trailing_lines', 'trim_whitespace'],
            \    'css': ['css-beautify', 'remove_trailing_lines', 'stylelint', 'trim_whitespace'],
            \    'desktop': ['remove_trailing_lines', 'trim_whitespace'],
            \    'html': ['remove_trailing_lines', 'tidy', 'trim_whitespace'],
            \    'java': ['clang-format', 'remove_trailing_lines', 'trim_whitespace'],
            \    'json': ['dprint', 'remove_trailing_lines', 'trim_whitespace'],
            \    'mail': ['remove_trailing_lines', 'trim_whitespace'],
            \    'make': ['remove_trailing_lines', 'trim_whitespace'],
            \    'markdown': ['dprint', 'remove_trailing_lines', 'trim_whitespace'],
            \    'PKGBUILD': ['remove_trailing_lines', 'shfmt', 'trim_whitespace'],
            \    'po': ['remove_trailing_lines', 'trim_whitespace'],
            \    'python': ['autoflake', 'autopep8', 'isort', 'remove_trailing_lines', 'ruff', 'trim_whitespace', 'yapf'],
            \    'sh': ['remove_trailing_lines', 'shfmt', 'trim_whitespace'],
            \    'systemd': ['remove_trailing_lines', 'trim_whitespace'],
            \    'tex': ['latexindent', 'remove_trailing_lines', 'trim_whitespace'],
            \    'text': ['remove_trailing_lines', 'trim_whitespace'],
            \    'toml': ['dprint', 'remove_trailing_lines', 'trim_whitespace'],
            \    'typescript': ['dprint', 'remove_trailing_lines', 'trim_whitespace'],
            \    'vim': ['remove_trailing_lines', 'trim_whitespace'],
            \    'xml': ['remove_trailing_lines', 'trim_whitespace', 'xmllint'],
            \    'yaml': ['remove_trailing_lines', 'trim_whitespace', 'yamlfmt'],
            \    'zsh': ['remove_trailing_lines', 'shfmt', 'trim_whitespace']
            \}
let g:ale_linter_aliases =
            \{
            \    'PKGBUILD': 'sh',
            \    'zsh': 'sh'
            \}
""" Language servers are handled by YouCompleteMe and thus not included here.
let g:ale_linters =
            \{
            \    'bib': ['bibclean'],
            \    'cpp': ['clangtidy'],
            \    'cmake': ['cmake_lint'],
            \    'css': ['stylelint'],
            \    'desktop': ['desktop_file_validate'],
            \    'gitcommit': ['gitlint'],
            \    'html': ['htmlhint', 'tidy'],
            \    'java': ['javac', 'pmd'],
            \    'json': ['jq'],
            \    'mail': [],
            \    'make': ['checkmake'],
            \    'markdown': ['markdownlint'],
            \    'PKGBUILD': ['shell', 'shellcheck'],
            \    'po': ['msgfmt'],
            \    'python': ['bandit', 'mypy', 'pycodestyle', 'pydocstyle', 'pyflakes', 'pyright', 'ruff', 'vulture'],
            \    'sh': ['shell', 'shellcheck'],
            \    'systemd': ['systemd_analyze'],
            \    'tex': ['chktex', 'lacheck'],
            \    'text': [],
            \    'toml': [],
            \    'typescript': ['biome'],
            \    'vim': ['vint'],
            \    'xml': ['xmllint'],
            \    'yaml': ['yamllint'],
            \    'zsh': ['shell', 'shellcheck']
            \}
let g:ale_linters_explicit = 1
let g:ale_virtualtext_cursor = 0

""" c
let g:ale_c_clangformat_options = '--style file:' . $XDG_CONFIG_HOME . '/clang/clang-format.yaml'

""" cmake
let g:ale_cmake_cmake_lint_options = '-c=' . $XDG_CONFIG_HOME . '/cmake-lang/cmake-lang.yaml'
let g:ale_cmake_cmakeformat_options = '-c=' . $XDG_CONFIG_HOME . '/cmake-lang/cmake-lang.yaml'

""" cpp
let g:ale_cpp_clangtidy_extra_options = '--config-file=' . $XDG_CONFIG_HOME . '/clang/clang-tidy.yaml'

""" css
let g:ale_css_css_beautify_options = '--config ' . $XDG_CONFIG_HOME . '/js-beautify/css-beautify.json'
let g:ale_css_stylelint_options = '--cache --cache-location ' . $XDG_CACHE_HOME . '/stylelint/ --config ' . $XDG_CONFIG_HOME . '/stylelint/stylelintrc.yaml'

""" dprint
let g:ale_dprint_config = $XDG_CONFIG_HOME . '/dprint/dprint.json'

""" html
let g:ale_html_htmlhint_options = '-c ' . $XDG_CONFIG_HOME . '/htmlhint/htmlhintrc.yaml'
let g:ale_html_tidy_options = '-config ' . $XDG_CONFIG_HOME . '/tidy/tidyrc -q'

""" java
let g:ale_java_pmd_options = '--cache ' . $XDG_CACHE_HOME . '/pmd/cache -R ' . $XDG_CONFIG_HOME . '/pmd/rules.xml'

""" markdown
let g:ale_markdown_markdownlint_executable = 'markdownlint-cli2'
let g:ale_markdown_markdownlint_options = '--config ' . $XDG_CONFIG_HOME . '/markdownlint/.markdownlint.yaml'

""" python
let g:ale_python_mypy_options = '--strict'
let g:ale_python_pycodestyle_options = '--max-line-length 120'
let g:ale_python_pyright_config =
            \{
            \    'pyright':
            \    {
            \        'disableLanguageServices': v:true,
            \        'disableOrganizeImports': v:false
            \    },
            \    'python':
            \    {
            \        'analysis':
            \        {
            \            'autoImportCompletions': v:true,
            \            'autoSearchPaths': v:true,
            \            'diagnosticMode': 'openFilesOnly',
            \            'diagnosticSeverityOverrides': {},
            \            'extraPaths': [],
            \            'logLevel': 'Information',
            \            'stubPath': '',
            \            'typeCheckingMode': 'strict',
            \            'typeshedPaths': [],
            \            'useLibraryCodeForTypes': v:true
            \        },
            \        'pythonPath': 'python',
            \        'venvPath': ''
            \    }
            \}
let g:ale_python_vulture_options = '--min-confidence 100'

""" sh
let g:ale_sh_shellcheck_options = '-a -Calways -o all -P SCRIPTDIR -S style -x'
let g:ale_sh_shfmt_options = '-ci -fn -i 4 -sr'

""" tex
let g:ale_tex_chktex_options = '-I -n 44'

""" typescript
let g:ale_biome_options = '--config-path ' . $XDG_CONFIG_HOME . '/biome/biome.json'

""" yaml
let g:ale_yaml_yamlfmt_options = '-conf ' . $XDG_CONFIG_HOME . '/yamlfmt/yamlfmt.yaml'
let g:ale_yaml_yamllint_options = '-c ' . $XDG_CONFIG_HOME . '/yamllint/yamllint.yaml'

"" vim-code-minimap
let g:minimap_auto_start = 1
let g:minimap_git_colors = 1
let g:minimap_highlight_search = 1
let g:minimap_width = 25

"" vim-gruvbox-community
let g:gruvbox_italic = 1

"" vim-nerdtree
let g:NERDTreeShowHidden = 1

"" vim-youcompleteme
let g:ycm_enable_semantic_highlighting = 1
""" Clang, jdt.ls, Jedi and TSServer are supported natively and therefore not included here.
let g:ycm_language_server =
            \[
            \    {
            \        'cmdline': ['autotools-language-server'],
            \        'filetypes': ['automake', 'config', 'make'],
            \        'name': 'autotools'
            \    },
            \    {
            \        'cmdline': ['cmake-language-server', 'start'],
            \        'filetypes': ['cmake'],
            \        'name': 'cmake'
            \    },
            \    {
            \        'cmdline': ['vscode-css-language-server', '--stdio'],
            \        'filetypes': ['css'],
            \        'name': 'css'
            \    },
            \    {
            \        'cmdline': ['vscode-html-language-server', '--stdio'],
            \        'filetypes': ['html'],
            \        'name': 'html'
            \    },
            \    {
            \        'cmdline': ['java-language-server'],
            \        'filetypes': ['java'],
            \        'name': 'java'
            \    },
            \    {
            \        'capabilities':
            \        {
            \            'textDocument':
            \            {
            \                'completion':
            \                {
            \                    'completionItem':
            \                    {
            \                        'snippetSupport': v:true
            \                    }
            \                }
            \            }
            \        },
            \        'cmdline': ['vscode-json-language-server', '--stdio'],
            \        'filetypes': ['json'],
            \        'name': 'json'
            \    },
            \    {
            \        'cmdline': ['marksman', 'server'],
            \        'filetypes': ['markdown'],
            \        'name': 'markdown'
            \    },
            \    {
            \        'cmdline': ['mutt-language-server'],
            \        'filetypes': ['conf', 'neomuttrc'],
            \        'name': 'neomuttrc'
            \    },
            \    {
            \        'cmdline': ['termux-language-server'],
            \        'filetypes': ['PKGBUILD'],
            \        'name': 'pkgbuild'
            \    },
            \    {
            \        'cmdline': ['requirements-language-server'],
            \        'filetypes': ['requirements'],
            \        'name': 'requirements'
            \    },
            \    {
            \        'cmdline': ['bash-language-server', 'start'],
            \        'filetypes': ['sh', 'zsh'],
            \        'name': 'shell'
            \    },
            \    {
            \        'cmdline': ['texlab'],
            \        'filetypes': ['tex'],
            \        'name': 'tex'
            \    },
            \    {
            \        'cmdline': ['tmux-language-server'],
            \        'filetypes': ['tmux'],
            \        'name': 'tmux'
            \    },
            \    {
            \        'cmdline': ['vim-language-server', '--stdio'],
            \        'filetypes': ['vim'],
            \        'name': 'vim'
            \    },
            \    {
            \        'capabilities':
            \        {
            \            'textDocument':
            \            {
            \                'completion':
            \                {
            \                    'completionItem':
            \                    {
            \                        'snippetSupport': v:true
            \                    }
            \                }
            \            },
            \            'workspace':
            \            {
            \                'configuration': v:true
            \            }
            \        },
            \        'cmdline': ['yaml-language-server', '--stdio'],
            \        'filetypes': ['yaml'],
            \        'name': 'yaml'
            \    }
            \]

"" Setup (The plugins need to be loaded at the end of the plugin configuration.)
call plug#begin($XDG_DATA_HOME . '/vim/plugged/')
Plug '/usr/share/vim/vimfiles/'
call plug#end()

" Autocommands
augroup vimrc
    autocmd!
    autocmd vimrc VimEnter * NERDTree | wincmd p
    autocmd vimrc BufEnter NERD_tree_* | execute 'normal R'
augroup end

" Basic
colorscheme gruvbox
filetype indent on
filetype plugin on
set autoindent
set autoread
set background=dark
set backspace=eol,indent,start
set breakindent
set cdhome
set encoding=utf-8
set laststatus=2
set list
set listchars=tab:>-,trail:~
" vint: -ProhibitSetNoCompatible
set nocompatible
set number
set shiftwidth=4
set smartindent
set termguicolors
set ttimeoutlen=10
syntax on

" Commands
set history=100
set wildmenu

" Cursor
set cursorline
set cursorlineopt=line,number
set scrolloff=5

" Search
set hlsearch
set ignorecase
set incsearch
set showmatch
set smartcase

" Shortcuts
nnoremap <C-q> :qa<CR>
nnoremap <C-t> :NERDTreeToggle<CR>

" Spell checking
highlight clear SpellBad
highlight SpellBad cterm=underline
set spell
set spelllang=de_de,en_gb

" Tabs
set expandtab
set smarttab
set tabstop=4

" XDG
set runtimepath^=$XDG_CONFIG_HOME/vim/
set runtimepath+=$XDG_DATA_HOME/vim/
set runtimepath+=$XDG_CONFIG_HOME/vim/after/

set packpath^=$XDG_DATA_HOME/vim/,$XDG_CONFIG_HOME/vim/
set packpath+=$XDG_CONFIG_HOME/vim/after/,$XDG_DATA_HOME/vim/after/

let g:netrw_home = $XDG_DATA_HOME . '/vim/'
call mkdir($XDG_DATA_HOME . '/vim/spell/', 'p')

set backupdir=$XDG_STATE_HOME/vim/backup/ | call mkdir(&backupdir, 'p')
set directory=$XDG_STATE_HOME/vim/swap/ | call mkdir(&directory, 'p')
set undodir=$XDG_STATE_HOME/vim/undo/ | call mkdir(&undodir, 'p')
set viewdir=$XDG_STATE_HOME/vim/view/ | call mkdir(&viewdir, 'p')

set viminfofile=$XDG_STATE_HOME/vim/viminfo

biome.json:

{
    "extends": [],
    "files": {
        "ignore": [],
        "ignoreUnknown": false,
        "include": ["*.ts"],
        "maxSize": 1048576
    },
    "formatter": {
        "enabled": false
    },
    "javascript": {
        "formatter": {},
        "globals": [],
        "parser": {
            "unsafeParameterDecoratorsEnabled": true
        }
    },
    "json": {
        "formatter": {
            "enabled": false
        },
        "parser": {
            "allowComments": false,
            "allowTrailingCommas": false
        }
    },
    "linter": {
        "enabled": true,
        "ignore": [],
        "include": ["*.ts"],
        "rules": {
            "a11y": {
                "all": true,
                "recommended": false
            },
            "all": true,
            "complexity": {
                "all": true,
                "noExcessiveCognitiveComplexity": "off",
                "recommended": false
            },
            "correctness": {
                "all": true,
                "noNodejsModules": "off",
                "recommended": false
            },
            "nursery": {
                "all": false,
                "recommended": false
            },
            "performance": {
                "all": true,
                "recommended": false
            },
            "recommended": false,
            "security": {
                "all": true,
                "recommended": false
            },
            "style": {
                "all": true,
                "noInferrableTypes": "off",
                "noNamespace": "off",
                "recommended": false,
                "useNamingConvention": "off"
            },
            "suspicious": {
                "all": true,
                "recommended": false
            }
        }
    },
    "organizeImports": {
        "enabled": false
    },
    "overrides": [],
    "vcs": {
        "enabled": false
    }
}

@redbmk
Copy link
Contributor Author

redbmk commented Jun 21, 2024

@Spixmaster

Why does Ale try to start the language server?

This is generally faster for linting because it can see changes as you type. Otherwise ALE would have to continually poll the check command or run it on file save or something.

Could you please try adding this line to see if it fixes the LSP for you?:

let g:ale_biome_lsp_project_root = $XDG_CONFIG_HOME . '/biome/biome.json'

I usually need to run :ALEStopAllLSPs and then save or :e the file to get config changes to trigger.

I wonder if the fixer should also use the same logic unless you're explicitly adding --config-path already. But I guess the fixer would run in the correct cwd I think so likely biome is already doing something similar.

I actually have some changes locally I haven't pushed up yet that change how the options work. I was thinking that since the only option shared across all commands is --config-path, then having the same options be used for both fixers and linters wouldn't make much sense.

@Spixmaster
Copy link
Contributor

Spixmaster commented Jun 21, 2024

This branch makes it work for me.

let g:ale_biome_lsp_project_root = $XDG_CONFIG_HOME . '/biome/biome.json'

was not even necessary for it but worked with it too. It does not even have to do anything with one of the searched files biome.json, biome.jsonc, package.json or .git as I renamed them. Maybe, the directory of the file is chosen then, hence bufname(a:buffer). I am not sufficient enough in the understanding to know that.

However, this works now with no configuration needed for me. Thank you very much.

@Spixmaster
Copy link
Contributor

@hsanson For me, this one works.

Copy link
Contributor

@hsanson hsanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but has some conflicts that need to be resolved before I can merge.

Since biome supports either `biome.json` or `biome.jsonc` config files,
we need to look for both when searching for the LSP project root. We can
also look for a package.json or .git folder to use. This uses mostly the
same logic as deno.
@redbmk
Copy link
Contributor Author

redbmk commented Jun 24, 2024

@hsanson Thanks! Just updated to fix the conflicts

Copy link
Contributor

@hsanson hsanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@hsanson hsanson merged commit ed0b036 into dense-analysis:master Jun 25, 2024
7 checks passed
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.

None yet

3 participants