Closed jcaffey closed 1 year ago
I tried adding nvim-treesitter.lua
with the options provided here: https://www.lazyvim.org/plugins/treesitter
Then adding "swift" to ensure_installed and enabling commentstring, but it still complains of empty commentstring in a swift file.
nvim-treesitter.lua
return {
"nvim-treesitter/nvim-treesitter",
version = false, -- last release is way too old and doesn't work on Windows
build = ":TSUpdate",
event = { "BufReadPost", "BufNewFile" },
dependencies = {
{
"nvim-treesitter/nvim-treesitter-textobjects",
init = function()
-- PERF: no need to load the plugin, if we only need its queries for mini.ai
local plugin = require("lazy.core.config").spec.plugins["nvim-treesitter"]
local opts = require("lazy.core.plugin").values(plugin, "opts", false)
local enabled = false
if opts.textobjects then
for _, mod in ipairs({ "move", "select", "swap", "lsp_interop" }) do
if opts.textobjects[mod] and opts.textobjects[mod].enable then
enabled = true
break
end
end
end
if not enabled then
require("lazy.core.loader").disable_rtp_plugin("nvim-treesitter-textobjects")
end
end,
},
},
keys = {
{ "<c-space>", desc = "Increment selection" },
{ "<bs>", desc = "Decrement selection", mode = "x" },
},
---@type TSConfig
opts = {
highlight = { enable = true },
indent = { enable = true },
ensure_installed = {
"bash",
"c",
"html",
"javascript",
"json",
"lua",
"luadoc",
"luap",
"markdown",
"markdown_inline",
"python",
"query",
"regex",
"tsx",
"swift",
"typescript",
"vim",
"vimdoc",
"yaml",
},
context_commentstring = {
enable = true,
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<C-space>",
node_incremental = "<C-space>",
scope_incremental = false,
node_decremental = "<bs>",
},
},
},
---@param opts TSConfig
config = function(_, opts)
if type(opts.ensure_installed) == "table" then
---@type table<string, boolean>
local added = {}
opts.ensure_installed = vim.tbl_filter(function(lang)
if added[lang] then
return false
end
added[lang] = true
return true
end, opts.ensure_installed)
end
require("nvim-treesitter.configs").setup(opts)
end,
}
Hey! That seems quite weird. I use Comment.nvim and commenting in Swift seems to work for me.
Could you try out :=require("ts_context_commentstring.internal").calculate_commentstring()
to see what it returns? It returns nil
for me, but I still get the // %s
when I use gcc
(not sure where that comes from tbh, maybe a default in Comment.nvim).
You could also try explicitly configuring this plugin for Swift like so:
require('nvim-treesitter.configs').setup {
-- ...
context_commentstring = {
enable = true,
enable_autocmd = false,
config = {
swift = '// %s', -- <-
},
},
However, I'm wondering if you actually need Treesitter context aware commenting for Swift. Maybe there's a way to configure mini.comment
to use // %s
in Swift files?
Thanks for taking a look. I tried your suggestions with no luck. I spent a couple hours on it and eventually gave up. My solution was to switch to NV chad... which is not a solution at all, but I've been wanting to check it out and I'm very happy to have comments back.
lazy-lock.json
Description
gcc
on a line in a .swift file shows error "option 'commentstring' is empty"I'm using lazyvim.org Neovim which comes with mini.comment. Is swift not supported? I'm sure I'm missing something stupid.
Steps to reproduce
:e somefile.swift
gcc
to comment lineExpected behavior
comment line
Actual behavior
option 'commentstring' is empty
Additional context
No response