summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/my/events.lua
blob: 933ba1999c85090e244c93efbcf9ddd619729fbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
local lsp = require("my.lsp")
local oil = require("oil")
local lint = require("lint")
local event = vim.api.nvim_create_autocmd
local command = vim.api.nvim_create_user_command

vim.api.nvim_create_augroup("my", {clear= true})
vim.api.nvim_create_augroup("conf#events", {clear= true})

event(
  "User",
  {group= "conf#events",
   pattern= { "ZoxideDirChanged" },
   callback= function()
     vim.schedule(function()
       oil.open(vim.fn.getcwd())
     end)
   end})

event(
  "BufReadPost",
  {group= "conf#events",
   pattern= { "*" },
   callback=function()
     local pattern = "'\\s\\+$'"
     vim.cmd("syn match TrailingWhitespace " .. pattern)
     vim.cmd("hi link TrailingWhitespace IncSearch")
   end})

event(
  "BufWritePost",
  {group= "conf#events",
   pattern={ "*" },
   callback=function()
     lint.try_lint()
     vim.schedule(function() vim.diagnostic.setloclist({open= false}) end)
   end})

local session_file = vim.fn.expand("~/.vimsession.vim")
event(
  "VimLeave",
  {group= "conf#events",
   pattern= { "*" },
   callback=function()
     vim.cmd("mksession! " .. session_file)
   end})

event(
  "LspAttach",
  {group = "conf#events",
   pattern = { "*" },
   callback = function(ev)
     lsp.attach({
       client = vim.lsp.get_client_by_id(ev.data.client_id),
       buf = ev.buf,
     })
   end})

event(
  "LspAttach",
  {group = "conf#events",
   pattern = { "*" },
   callback = function(ev)
     lsp.attach({
       client = vim.lsp.get_client_by_id(ev.data.client_id),
       buf = ev.buf,
     })
   end})

-- filetypes

event(
  "FileType", {
    group="conf#events",
    pattern={ "go", "gomod", "gowork", "gotmpl" },
    callback=function(ev)
      vim.lsp.start({
        name="gopls",
        cmd={ "gopls" },
        root_dir=vim.fs.root(ev.buf, {"go.work", "go.mod", ".git"})
      })
    end,
  })

event(
  "FileType", {
    group="conf#events",
    pattern={ "python" },
    callback=function(ev)
      vim.lsp.start({
        name="basedpyright",
        cmd={ "basedpyright-langserver", "--stdio" },
        settings={
          basedpyright = {
            analysis = {
              autoSearchPaths = true,
              diagnosticMode = "openFilesOnly",
              useLibraryCodeForTypes = true,
              autoImportCompletions = true,
              inlayHints = {
                variableTypes = true,
                callArgumentNames = true,
                functionReturnTypes = true,
                genericTypes = true,
              },
            },
          },
        },
        root_dir=vim.fs.root(ev.buf, {
          'pyproject.toml',
          'setup.py',
          'setup.cfg',
          'requirements.txt',
          'Pipfile',
          'pyrightconfig.json',
          '.git',
        })
      })
    end,
  })