std.fs.File.close() freezes Neovim

This problem has been plaguing me for months, and I have been apprehensive to even bring it up because it is both petty, and I suspect is a configuration error with my own setup, but I have been unable to pin down exactly where the problem is stemming from, and it is somewhat difficult and long-winded to explain via text.

The “tldr” version is that I just need to know if this occurs to anyone else so I can isolate this down to a ZLS problem, my Neovim plugins, or combination of both.

The Problem
Using Neovim on Arch Linux, when writing Zig code (both 0.13 and the master branch, though untested in previous version), typing file.close() causes Neovim to instantly lockup. No errors are generated, and I must force-terminate the application via external commands. Consider the following:

const std = @import("std");
var file = try std.fs.openFileAbsolute("/path/to/file.ext");
defer file.close();
//          ^

The instant that close becomes the currently selected autocomplete, the application instantly freezes, never to become responsive again. This only occurs with close(), no other function, for any other type. A close() function on another type works perfectly fine, it only occurs with std.fs.File.

My Neovim setup is nothing too complicated. Regarding anything LSP or auto-complete related, I don’t use anything exotic:

  • blink.cmp
  • fzf-lua
  • nvim-lspconfig
  • friendly-snippets

There are obviously some others, but nothing related to the LSP or the autocomplete, which seems to be what is triggering it.

lspconfg
{
  "neovim/nvim-lspconfig",
  ---@class PluginLspOpts
  opts = {
    inlay_hints = { enabled = true },
    ---@type lspconfig.options
    servers = {
      -- Zig Language Server
      -- https://github.com/zigtools/zls/blob/master/schema.json
      zls = {
        filetypes = { "zig", "zon" },
        enable_snippets = true,
        enable_argument_placeholders = true,
        completion_label_details = true,
        semantic_tokens = "full",
        inlay_hints_show_variable_type_hints = true,
        inlay_hints_show_struct_literal_field_type = true,
        inlay_hints_show_parameter_name = true,
        inlay_hints_show_builtin = true,
        inlay_hints_exclude_single_argument = false,
        inlay_hints_hide_redundant_param_names = true,
        inlay_hints_hide_redundant_param_names_last_token = true,
        force_autofix = true,
        warn_style = true,
      },
    },
  },
},
blink.cmp
  {
    "saghen/blink.cmp",
    opts = {
      keymap = {
        preset = "super-tab",
      },

      completion = {

        keyword = { range = "full" },
        ghost_text = { enabled = true },
        -- Show documentation when selecting a completion item
        documentation = {
          auto_show = true,
          auto_show_delay_ms = 500,
        },
        accept = { auto_brackets = { enabled = true } },

        -- trigger = { show_in_snippet = false },
        list = {
          selection = {
            preselect = function(_)
              return not blink_cmp.snippet_active({ direction = 1 })
            end,
            -- preselect = true,
            auto_insert = false,
          },
        },

        menu = {
          draw = {
            gap = 1,
            align_to = "label",
            -- Use treesitter to highlight the label text for the given list of sources
            treesitter = { "lsp" },
            -- Components to render, grouped by column
            columns = { { "kind_icon" }, { "label", "label_description", gap = 1 } },
          },
        },

        -- Display a preview of the selected item on the current line
        -- ghost_text = { enabled = true },
      },

      -- Experimental signature help support
      signature = { enabled = true },
    },

I apologize for the muddled verbose question, and its unimportance, but I hope someone can offer me some insights.

3 Likes

I suggest commenting out your config and seeing if it persists. If it doesn’t, you know your issue is in there, if it still persists then it’s either nvim or zls problem.
Speaking of which, what version of zig and zls are you using

1 Like

I haven’t tested it with any version before prior to 0.13, but when using Zig 0.13 with ZLS 0.13 it does it, as well as with the current master version of each. If it were only occurring on the dev branches, I would just write it off as that being the problem, but it happens on the stable (for lack of a better word) 0.13 versions as well.

The lack of any useful error is the most frustrating part. I can work around it by simply typing .close() first, and then prepending it with the variable name, so it really isn’t worth it to me to methodically going through every configuration setting one-by-one.

I can recreate it, starts spinning at .cl
I left it with fans roaring for a few minutes and it came eventually came back, but spun again on the s. Eventually came back for me to finish the close().

zls 0.13.0
zig master
pretty much vanilla lazyvim
nvim 0.11
arch

3 Likes

A large portion of my config has been “borrowed” directly from lazyvim.
I wonder if that might be the culprit, specifically with blink.cmp.

Looks like it.

I reverted to nvim-cmp, and it didn’t lock up.
Went back to blink and locks-up(rather spinning for a few minutes) again.

Hope this helps

2 Likes

I reverted to nvim-cmp, and it didn’t lock up.

I just confirmed. Well, now I guess we know where the problem lies. I will see if I can narrow the problem down further and submit a report/fix upstream if necessary.

Thank you much.

1 Like

No prob.

Looks like this could be the same issue over here: https://github.com/zigtools/zls/issues/2173

also:

https://github.com/Saghen/blink.cmp/issues/1039

3 Likes

Good find.

I chased the rabbit-hole to the second issue you added, but you apparently already found it. It seems to indicate an issue with TreeSitter’s Zig parser. I haven’t found it reported to TS yet, but I am still going through those issues.

They did mention a workaround by setting the following settings to false, which I will leave here for anyone else who stumbles into this thread.

completion.documentation.treesitter_highlighting
signature.window.treesitter_highlighting

I would personally prefer to just deal with it than disable those, and workaround it by being mindful of how I type the close function.

1 Like

Yip, I did the changes that Nico made to docs.lua and seems sorted from my side, will wait for the fix. (https://github.com/Saghen/blink.cmp/compare/main…NicoElbers:blink.cmp:main)