Skip to content

Commit

Permalink
Shell/Vim: stop (and restart) LSP mode RuboCop after .rubocop.yml u…
Browse files Browse the repository at this point in the history
…pdates
  • Loading branch information
kg8m committed Jul 27, 2024
1 parent 1f8f81f commit b7dbe04
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions .config/vim/autoload/kg8m/plugin/lsp/servers.vim
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ def ExtraConfigForLuaLanguageServer(): dict<any>
enddef

# gem install rubocop
# cf. .config/vim/autoload/kg8m/util/daemons.vim
def RegisterRubocop(): void
if $USE_RUBOCOP_LSP !=# "0" && filereadable(".rubocop.yml")
RegisterServer({
Expand Down
14 changes: 8 additions & 6 deletions .config/vim/autoload/kg8m/util/daemons.vim
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
vim9script

import autoload "kg8m/plugin/lsp/servers.vim" as lspServers

export def Setup(): void
augroup vimrc-util-daemons
autocmd!
autocmd BufWritePost .eslintrc.*,package.json,tsconfig.json RestartEslintD()
autocmd BufWritePost .rubocop.yml RestartRubocopServer()
autocmd BufWritePost .rubocop.yml RestartRubocopDaemon()
autocmd BufWritePost */config/routes.rb,*/config/routes/*.rb UpdateRoutingDependencies()
augroup END
enddef
Expand All @@ -15,9 +17,9 @@ export def RestartEslintD(): void
endif
enddef

export def RestartRubocopServer(): void
if IsRubocopServerAvailable()
job_start(["rubocop", "--restart-server"])
export def RestartRubocopDaemon(): void
if IsRubocopLspAvailable()
LspStopServer rubocop
elseif IsRubocopDaemonAvailable()
job_start(["rubocop-daemon", "restart"])
endif
Expand All @@ -27,8 +29,8 @@ def IsEslintDAvailable(): bool
return !!executable("eslint_d")
enddef

def IsRubocopServerAvailable(): bool
return !!executable("rubocop") && !!(system("rubocop --server-status") =~# '^RuboCop server')
def IsRubocopLspAvailable(): bool
return lspServers.IsAvailable("rubocop")
enddef

def IsRubocopDaemonAvailable(): bool
Expand Down

0 comments on commit b7dbe04

Please sign in to comment.