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

feat: remove overflow warning #68

Merged
merged 1 commit into from
Jul 1, 2024
Merged

feat: remove overflow warning #68

merged 1 commit into from
Jul 1, 2024

Conversation

gbprod
Copy link
Owner

@gbprod gbprod commented Jun 4, 2024

This PR removes the detection of lines not following the 50/72 rule.

After a lot of discussions and thinking, I've decided that this rule should not be bundled with the tree-sitter parser.

Main reasons are:

  • This is annoying for users who don't follow this rule and it's not easy to disable it ;
  • This is more the job of a linter like gitlint or commitlint or query;
  • This is not a syntax rule, but a convention rule
  • I prefer to keep the parser as simple as possible
  • After merging this PR, it will be easy to recreate this behavior using a query:
((subject) @comment.error
  (#vim-match? @comment.error ".\{50,}")
  (#offset! @comment.error 0 50 0 0))

((message_line) @comment.error
  (#vim-match? @comment.error ".\{72,}")
  (#offset! @comment.error 0 72 0 0))

References:

gbprod added a commit to gbprod/nvim-treesitter that referenced this pull request Jun 26, 2024
This commit remove the highlight of the overflow node in gitcommit syntax
introduced [by this PR](nvim-treesitter#6222).
This node will be removed when [this PR](gbprod/tree-sitter-gitcommit#68)
will be merge.
gbprod added a commit to gbprod/nvim-treesitter that referenced this pull request Jun 26, 2024
This commit remove the highlight of the overflow node in gitcommit syntax
introduced [by this PR](nvim-treesitter#6222).
This node will be removed when [this PR](gbprod/tree-sitter-gitcommit#68)
will be merge.
clason pushed a commit to nvim-treesitter/nvim-treesitter that referenced this pull request Jun 27, 2024
This commit remove the highlight of the overflow node in gitcommit syntax
introduced [by this PR](#6222).
This node will be removed when [this PR](gbprod/tree-sitter-gitcommit#68)
will be merge.
@gbprod gbprod merged commit aa5c279 into main Jul 1, 2024
3 checks passed
@gbprod gbprod deleted the feat-remove-5072 branch July 1, 2024 15:12
@Flimm
Copy link

Flimm commented Jul 5, 2024

Even though I miss the old behaviour, I agree with this decision. I think your reasoning is sound. Thank you for introducing me to gitlint! For the lurkers, in order to ensure gitlint checks that the title line does not exceed 50 characters, add these lines to your .gitlint configuration file:

[title-max-length]
line-length=50

deathlyfrantic added a commit to deathlyfrantic/.config that referenced this pull request Jul 11, 2024
The "overflow" node type was removed in this PR:
gbprod/tree-sitter-gitcommit#68
aaronkollasch added a commit to aaronkollasch/dotfiles that referenced this pull request Jul 12, 2024
benelan added a commit to benelan/dotfiles that referenced this pull request Jul 29, 2024
- Fix monitor and mouse annoyances in i3wm
- Fix i3lock setup
- Get cmp-git working in markdown files created by `gh`.
- Disable cmp-git in markdown files not created by `gh`.
- Resolve treesitter-text-objects lazy loading issue
- Add back the treesitter query for line length in git commit buffers
- Various other small improvements

diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json
index eae3dcbd..1948ec58 100644
--- a/.config/nvim/lazy-lock.json
+++ b/.config/nvim/lazy-lock.json
@@ -1,7 +1,7 @@
 {
   "CopilotChat.nvim": { "branch": "canary", "commit": "92bc7b5e564c23b12b2ed41dd7657fdafe39d95f" },
   "LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" },
-  "SchemaStore.nvim": { "branch": "main", "commit": "623df28bf9a2661d9d5a0f391bf30bdd8f8de62b" },
+  "SchemaStore.nvim": { "branch": "main", "commit": "4abc1ab13ad5031049864cba0bfaec06a908e7e5" },
   "cellular-automaton.nvim": { "branch": "main", "commit": "11aea08aa084f9d523b0142c2cd9441b8ede09ed" },
   "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
   "cmp-dictionary": { "branch": "main", "commit": "7144ce4bb2abc61a474cfdb3bb652a9ae82079e4" },
@@ -18,7 +18,7 @@
   "fidget.nvim": { "branch": "main", "commit": "d855eed8a06531a7e8fd0684889b2943f373c469" },
   "friendly-snippets": { "branch": "main", "commit": "00ebcaa159e817150bd83bfe2d51fa3b3377d5c4" },
   "gitsigns.nvim": { "branch": "main", "commit": "f4928ba14eb6c667786ac7d69927f6aee6719f1e" },
-  "gp.nvim": { "branch": "main", "commit": "25ef1e5839669c3cf4c15b12646c54afbaff1aea" },
+  "gp.nvim": { "branch": "main", "commit": "827d5e32ff7b7108cf8e476b4d7d16a72ec5f293" },
   "harpoon": { "branch": "harpoon2", "commit": "e76cb03c420bb74a5900a5b3e1dde776156af45f" },
   "lazy.nvim": { "branch": "main", "commit": "839f9e78e78dc935b1188fb16583365991739c51" },
   "markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" },
@@ -38,7 +38,7 @@
   "nvim-lspconfig": { "branch": "master", "commit": "fa6c2a64100c6f692bbec29bbbc8ec2663c9e869" },
   "nvim-nio": { "branch": "master", "commit": "a428f309119086dc78dd4b19306d2d67be884eee" },
   "nvim-rulebook": { "branch": "main", "commit": "a962cc98bf1a5ba564358396b386f1d938b53366" },
-  "nvim-treesitter": { "branch": "master", "commit": "debf5816eee21b7d51025ef17ba0647386226cb5" },
+  "nvim-treesitter": { "branch": "master", "commit": "9d252d00210ed8d43197ef048daa94e6dc821bd6" },
   "nvim-treesitter-context": { "branch": "master", "commit": "8198ad4b01ca64b6f5c7a7253f52df3fe329be46" },
   "nvim-treesitter-textobjects": { "branch": "master", "commit": "34867c69838078df7d6919b130c0541c0b400c47" },
   "nvim-web-devicons": { "branch": "master", "commit": "e612de3d3a41a6b7be47f51e956dddabcbf419d9" },
@@ -51,7 +51,7 @@
   "telescope.nvim": { "branch": "master", "commit": "79552ef8488cb492e0f9d2bf3b4e808f57515e35" },
   "treesj": { "branch": "main", "commit": "275f83c81a5a1f5ae23c1eac30c4ac28beebbca2" },
   "trouble.nvim": { "branch": "main", "commit": "6efc446226679fda0547c0fd6a7892fd5f5b15d8" },
-  "ts-comments.nvim": { "branch": "main", "commit": "8c21ae09c34ef8b82f2c6d2a87f57c3da33bb5e5" },
+  "ts-comments.nvim": { "branch": "main", "commit": "0090cacf89bc52e4eddb911bc6c33b12411b95f7" },
   "typescript-tools.nvim": { "branch": "master", "commit": "f8c2e0b36b651c85f52ad5c5373ff8b07adc15a7" },
   "vim-dirtytalk": { "branch": "master", "commit": "aa57ba902b04341a04ff97214360f56856493583" },
   "vim-flog": { "branch": "master", "commit": "36c60cbdb69c169ee44c085ce8d3f2f035a8658e" },
diff --git a/.config/nvim/lua/jamin/plugins/completion.lua b/.config/nvim/lua/jamin/plugins/completion.lua
index 83585fab..26de4611 100644
--- a/.config/nvim/lua/jamin/plugins/completion.lua
+++ b/.config/nvim/lua/jamin/plugins/completion.lua
@@ -30,10 +30,21 @@ return {
   {
     "petertriho/cmp-git",
     ft = { "markdown", "gitcommit", "octo" },
-    opts = {
-      filetypes = { "markdown", "gitcommit", "octo" },
-      github = { issues = { state = "all" }, pull_requests = { state = "all" } },
-    },
+    opts = { filetypes = { "markdown", "gitcommit", "octo" } },
+    config = function(_, opts)
+      require("cmp_git").setup(opts)
+
+      -- The gh cli creates markdown files in `/tmp` when creating/editing issues/prs/comments. Not
+      -- sure why, but cwd ends up being `/tmp` when gh opens the editor. That prevents cmp-git from
+      -- working, since it doesn't know the repo to query for completion items.
+      vim.api.nvim_create_autocmd("FileType", {
+        pattern = { "markdown" },
+        group = vim.api.nvim_create_augroup("jamin_git_cmp_gh_hack", {}),
+        callback = function(ev)
+          if string.match(ev.file, "/tmp/%d+%.md") then vim.cmd.cd("-") end
+        end,
+      })
+    end,
   },

   -----------------------------------------------------------------------------
@@ -228,7 +239,16 @@ return {
           { name = "luasnip", group_index = 1 },
           { name = "nvim_lsp", group_index = 1 },
           { name = "path", group_index = 1 },
-          { name = "git", group_index = 1 },
+          {
+            name = "git",
+            entry_filter = function(_, ctx)
+              return not (
+                ctx.filetype == "markdown"
+                and not string.match(vim.api.nvim_buf_get_name(ctx.bufnr), "/tmp/%d+%.md")
+              )
+            end,
+            group_index = 1,
+          },
           { name = "buffer", group_index = 1, keyword_length = 2 },
           { name = "tmux", group_index = 1, keyword_length = 2 },
           -- only show ripgrep/spell/dictionary if there are no results from other sources
diff --git a/.config/nvim/lua/jamin/plugins/git.lua b/.config/nvim/lua/jamin/plugins/git.lua
index 6243cf12..301157b7 100644
--- a/.config/nvim/lua/jamin/plugins/git.lua
+++ b/.config/nvim/lua/jamin/plugins/git.lua
@@ -231,6 +231,11 @@ return {
         function() require("gitsigns").blame_line({ full = true }) end,
         desc = "Git blame line (gitsigns)",
       },
+      {
+        "<leader>hB",
+        function() require("gitsigns").blame() end,
+        desc = "Git blame buffer (gitsigns)",
+      },
       {
         "<leader>htb",
         function() require("gitsigns").toggle_current_line_blame() end,
diff --git a/.config/nvim/lua/jamin/plugins/notes.lua b/.config/nvim/lua/jamin/plugins/notes.lua
index 7cd5522e..d409dd5e 100644
--- a/.config/nvim/lua/jamin/plugins/notes.lua
+++ b/.config/nvim/lua/jamin/plugins/notes.lua
@@ -27,6 +27,7 @@ return {
       return {
         filetypes = { md = true, rmd = true, mdx = true, markdown = true },
         to_do = { symbols = { " ", "x" } },
+        silent = true,
         links = {
           style = link_style,
           transform_explicit = function(text) return text:gsub(" ", "-"):lower() end,
@@ -45,7 +46,7 @@ return {
           MkdnCreateLinkFromClipboard = { { "n", "v" }, "<leader>P" },
           MkdnToggleToDo = { { "n", "v" }, "<leader>m<Tab>" },
           MkdnUpdateNumbering = { "n", "<leader>mn" },
-          MkdnMoveSource = { "n", "<leader>mR" },
+          MkdnMoveSource = { "n", "<leader>mrn" },
           MkdnTableNewRowBelow = { "n", "<leader>mir" },
           MkdnTableNewRowAbove = { "n", "<leader>miR" },
           MkdnTableNewColAfter = { "n", "<leader>mic" },
diff --git a/.config/nvim/lua/jamin/plugins/treesitter.lua b/.config/nvim/lua/jamin/plugins/treesitter.lua
index 71534a28..5929d82b 100644
--- a/.config/nvim/lua/jamin/plugins/treesitter.lua
+++ b/.config/nvim/lua/jamin/plugins/treesitter.lua
@@ -10,10 +10,6 @@ return {
     opts = { use_default_keymaps = false, max_join_length = 500 },
   },

-  -----------------------------------------------------------------------------
-  -- more text objects
-  { "nvim-treesitter/nvim-treesitter-textobjects", lazy = true },
-
   -----------------------------------------------------------------------------
   -- set commentstring based on treesitter node
   { "folke/ts-comments.nvim", event = "VeryLazy", opts = {} },
@@ -29,8 +25,6 @@ return {
     opts = {
       multiline_threshold = 1,
       max_lines = 6,
-      mode = "cursor",
-      -- separator = "─",
     },

     config = function(_, opts)
@@ -58,6 +52,9 @@ return {
   -- syntax tree parser/highlighter engine
   {
     "nvim-treesitter/nvim-treesitter",
+    dependencies = {
+      "nvim-treesitter/nvim-treesitter-textobjects", -- more text objects
+    },
     build = ":TSUpdate",
     cmd = { "TSUpdateSync", "TSUpdate", "TSInstall" },
     event = "BufReadPost",
@@ -89,7 +86,6 @@ return {
       return {
         ensure_installed = res.treesitter_parsers,
         indent = { enable = true },
-        autotag = { enable = true },
         query_linter = { enable = true },

         highlight = {
@@ -185,13 +181,7 @@ return {

     config = function(_, opts)
       require("nvim-treesitter.configs").setup(opts)
-      vim.schedule(
-        function()
-          require("lazy").load({
-            plugins = { "nvim-treesitter-textobjects", "nvim-treesitter-context" },
-          })
-        end
-      )
+      vim.schedule(function() require("lazy").load({ plugins = { "nvim-treesitter-context" } }) end)
     end,
   },
 }
diff --git a/.config/nvim/lua/jamin/resources.lua b/.config/nvim/lua/jamin/resources.lua
index 192e8539..8bbc00d0 100644
--- a/.config/nvim/lua/jamin/resources.lua
+++ b/.config/nvim/lua/jamin/resources.lua
@@ -123,7 +123,9 @@ M.mason_packages = {
 M.treesitter_parsers = {
   "astro",
   "bash",
+  "comment",
   "css",
+  -- "csv",
   "diff",
   "dockerfile",
   "git_rebase",
@@ -134,13 +136,14 @@ M.treesitter_parsers = {
   -- "gowork",
   "graphql",
   "html",
-  "http",
+  -- "http",
   -- "ini",
   "javascript",
   "jsdoc",
   "json",
   "json5",
   "jsonc",
+  -- "jq",
   -- "latex",
   "lua",
   "luadoc",
diff --git a/.config/nvim/queries/gitcommit/highlights.scm b/.config/nvim/queries/gitcommit/highlights.scm
new file mode 100644
index 00000000..fdc5247a
--- /dev/null
+++ b/.config/nvim/queries/gitcommit/highlights.scm
@@ -0,0 +1,10 @@
+; extends
+; gbprod/tree-sitter-gitcommit#68
+
+((subject) @comment.warning
+  (#vim-match? @comment.warning ".\{50,}")
+  (#offset! @comment.warning 0 50 0 0))
+
+((message_line) @comment.warning
+  (#vim-match? @comment.warning ".\{72,}")
+  (#offset! @comment.warning 0 72 0 0))
diff --git a/.dotfiles/shell/exports.sh b/.dotfiles/shell/exports.sh
index 26a5bd14..d41ca39e 100644
--- a/.dotfiles/shell/exports.sh
+++ b/.dotfiles/shell/exports.sh
@@ -210,13 +210,14 @@ if supports fff; then
 fi

 # https://github.com/meiji163/gh-notify
-export GH_NOTIFY_MARK_READ_KEY="alt-backspace"
-export GH_NOTIFY_MARK_ALL_READ_KEY="ctrl-delete"
-export GH_NOTIFY_OPEN_BROWSER_KEY="ctrl-o"
 export GH_NOTIFY_COMMENT_KEY="alt-c"
 export GH_NOTIFY_VIEW_DIFF_KEY="alt-d"
 export GH_NOTIFY_VIEW_PATCH_KEY="alt-D"
+export GH_NOTIFY_TOGGLE_PREVIEW_KEY="alt-p"
 export GH_NOTIFY_RESIZE_PREVIEW_KEY="alt-P"
+export GH_NOTIFY_MARK_READ_KEY="alt-x"
+export GH_NOTIFY_MARK_ALL_READ_KEY="alt-backspace"
+export GH_NOTIFY_OPEN_BROWSER_KEY="ctrl-o"

 # my tools {{{1
 supports matpat && export MATPAT_OPEN_CMD="$BROWSER"
@cameronr
Copy link

((subject) @comment.error
  (#vim-match? @comment.error ".\{50,}")
  (#offset! @comment.error 0 50 0 0))

((message_line) @comment.error
  (#vim-match? @comment.error ".\{72,}")
  (#offset! @comment.error 0 72 0 0))

Could you share how to use the above? I can paste it into :EditQuery but it doesn't seem to highlight anything. I liked the previous behavior and am interested in reproducing it.

Thanks!

@gbprod
Copy link
Owner Author

gbprod commented Aug 13, 2024

You should use :TSEditQueryUserAfter highlight gitcommit and add :

;; extends

((subject) @comment.error
  (#vim-match? @comment.error ".\{50,}")
  (#offset! @comment.error 0 50 0 0))

((message_line) @comment.error
  (#vim-match? @comment.error ".\{72,}")
  (#offset! @comment.error 0 72 0 0))

@cameronr
Copy link

Thanks for the quick response. Unfortunately, I still must be missing something :( I added the above (saved and quit) but i'm still not seeing any highlighting. This is what I see when i run git commit and type in a subject and message line that are too long:

Screenshot 2024-08-13 at 17 20 39

Any help is greatly appreciated!

@gbprod
Copy link
Owner Author

gbprod commented Aug 14, 2024

What's your highlight for @comment.error? Can you share the result of hi @comment.error?
What's your color scheme?

@cameronr
Copy link

cameronr commented Aug 14, 2024

@comment.error is a red color:

:hi @comment.error
@comment.error xxx guifg=#db4b4b

I'm using folke/tokyonight with the night style. Trying other color schemes in a live preview doesn't highlight the error either. This is on nvim 0.10.1 on macOS if that's relevant.

@cameronr
Copy link

cameronr commented Aug 25, 2024

Figured it out, it's highlights not highlight, so command should be:

:TSEditQueryUserAfter highlights gitcommit

Thanks for the help!

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.

3 participants