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

Language additions and sorting filetypes #78

Merged
merged 4 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/nvim-ts-context-commentstring.txt
JoosepAlviste marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Currently, the following languages are supported when they are injected with
language tree (see `lua/ts_context_commentstring/internal.lua`):

- `astro`
- `c`
- `css`
- `glimmer`
- `graphql`
Expand All @@ -28,13 +29,16 @@ language tree (see `lua/ts_context_commentstring/internal.lua`):
- `python`
- `rescript`
- `scss`
- `shell`
- `sql`
- `solidity`
- `svelte`
- `tsx`
- `twig`
- `typescript`
- `vim`
- `vue`
- `zsh`

This means that in any filetype, if the given languages are injected, this
plugin should detect them and correctly set the 'commentstring'. For example,
Expand Down
40 changes: 23 additions & 17 deletions lua/ts_context_commentstring/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ local M = {}
---@class ts_context_commentstring.Config
---@field enable_autocmd boolean
---@field custom_calculation? fun(node: TSNode, language_tree: LanguageTree): string
---@field languages ts_context_commentstring.LanguagesConfig
---@field config ts_context_commentstring.LanguagesConfig
---@field commentary_integration ts_context_commentstring.CommentaryConfig

Expand All @@ -56,28 +57,30 @@ M.config = {
CommentaryUndo = 'gcu',
},

-- TODO: We should probably rename this as having a "config" key inside
-- "config" is probably confusing. Maybe "languages"?
config = {
languages = {
-- Languages that have a single comment style
typescript = { __default = '// %s', __multiline = '/* %s */' },
css = '/* %s */',
scss = { __default = '// %s', __multiline = '/* %s */' },
php = { __default = '// %s', __multiline = '/* %s */' },
html = '<!-- %s -->',
svelte = '<!-- %s -->',
vue = '<!-- %s -->',
astro = '<!-- %s -->',
handlebars = '{{! %s }}',
c = { __default = '// %s', __multiline = '/* %s */' },
css = '/* %s */',
glimmer = '{{! %s }}',
graphql = '# %s',
handlebars = '{{! %s }}',
html = '<!-- %s -->',
lua = { __default = '-- %s', __multiline = '--[[ %s ]]' },
vim = '" %s',
sql = '-- %s',
twig = '{# %s #}',
python = { __default = '# %s', __multiline = '""" %s """' },
nix = { __default = '# %s', __multiline = '/* %s */' },
php = { __default = '// %s', __multiline = '/* %s */' },
python = { __default = '# %s', __multiline = '""" %s """' },
rescript = { __default = '// %s', __multiline = '/* %s */' },
scss = { __default = '// %s', __multiline = '/* %s */' },
sh = '# %s',
solidity = { __default = '// %s', __multiline = '/* %s */' },
sql = '-- %s',
svelte = '<!-- %s -->',
twig = '{# %s #}',
typescript = { __default = '// %s', __multiline = '/* %s */' },
vim = '" %s',
vue = '<!-- %s -->',
zsh = '# %s',

-- Languages that can have multiple types of comments
tsx = {
Expand All @@ -92,9 +95,12 @@ M.config = {
spread_element = { __default = '// %s', __multiline = '/* %s */' },
},
},

---@deprecated
JoosepAlviste marked this conversation as resolved.
Show resolved Hide resolved
config = {},
}

M.config.config.javascript = M.config.config.tsx
M.config.languages.javascript = M.config.languages.tsx

---@param config? ts_context_commentstring.Config
function M.update(config)
Expand All @@ -113,7 +119,7 @@ end

---@return ts_context_commentstring.LanguagesConfig
function M.get_languages_config()
return M.config.config
return vim.tbl_extend('keep', M.config.languages, M.config.config)
JoosepAlviste marked this conversation as resolved.
Show resolved Hide resolved
JoosepAlviste marked this conversation as resolved.
Show resolved Hide resolved
end

return M