From c83ee94e8fcf27dd5553000290dddc44404f97a0 Mon Sep 17 00:00:00 2001 From: Sergio Ribera <56278796+SergioRibera@users.noreply.github.com> Date: Tue, 26 Dec 2023 17:22:52 -0400 Subject: [PATCH] feat: add content variable into documentation --- README.md | 29 ++++++++++++++++++----------- lua/cmp-dotenv/dotenv.lua | 2 +- lua/cmp-dotenv/option.lua | 1 + 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 90a02c7..90f6617 100755 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ cmp.setup { item_kind = cmp.lsp.CompletionItemKind.Variable, eval_on_confirm = false, show_documentation = true, + show_content_on_docs = true, documentation_kind = 'markdown', dotenv_environment = '.*', file_priority = function(a, b) @@ -43,16 +44,17 @@ cmp.setup { ## Options -| name | default | description | -|--------------------|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| path | '.' | The path where to look for the files | -| load_shell | true | Do you want to load shell variables? | -| item_kind | [Variable](https://github.com/hrsh7th/nvim-cmp/blob/main/lua/cmp/types/lsp.lua#L178) | What kind of suggestion will cmp make? | -| eval_on_confirm | false | When you confirm the completion, do you want the variable or the value? | -| show_documentation | true | Do you want to see the documentation that has the variable? | -| documentation_kind | 'markdown' | What did you write the variable documentation on? | -| dotenv_environment | '.*' | Which variable environment do you want to load? `.*` by default loads all of them, this variable accepts regex, some suggestions I can give you are `example`, `local` or `development`. | -| file_priority | function | With this function you define the upload priority, by default it prioritizes the local variables, this responds to the callback of a computer for the found files. | +| name | default | description | +|----------------------|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| path | '.' | The path where to look for the files | +| load_shell | true | Do you want to load shell variables? | +| item_kind | [Variable](https://github.com/hrsh7th/nvim-cmp/blob/main/lua/cmp/types/lsp.lua#L178) | What kind of suggestion will cmp make? | +| eval_on_confirm | false | When you confirm the completion, do you want the variable or the value? | +| show_documentation | true | Do you want to see the documentation that has the variable? | +| show_content_on_docs | true | Allows to preview the content in the documentation popup with the prefix of `Content: `. | +| documentation_kind | 'markdown' | What did you write the variable documentation on? | +| dotenv_environment | '.*' | Which variable environment do you want to load? `.*` by default loads all of them, this variable accepts regex, some suggestions I can give you are `example`, `local` or `development`. | +| file_priority | function | With this function you define the upload priority, by default it prioritizes the local variables, this responds to the callback of a computer for the found files. | ## Advanced Usage @@ -79,7 +81,12 @@ dotenv.set_env_variable(name, value, docs or nil) -- configuration you have from the files or the shell, -- I do not recommend calling this function as it is -- usually called by default by cmp. -dotenv.load(opts) +dotenv.load() + +-- You need to do this before calling the load function +-- or else `load()` will take the cmp configuration or the default one. +local option = require('cmp-dotenv.option') +option.set(opts) ``` ## Contributing diff --git a/lua/cmp-dotenv/dotenv.lua b/lua/cmp-dotenv/dotenv.lua index c19bf0d..b74b531 100644 --- a/lua/cmp-dotenv/dotenv.lua +++ b/lua/cmp-dotenv/dotenv.lua @@ -67,7 +67,7 @@ function M.as_completion() -- Show documentation if `show_documentation_window` is true documentation = opts.show_documentation and { kind = opts.documentation_kind, - value = v.docs .. '\n\nContent: ' .. v.value, + value = v.docs .. opts.show_content_on_docs and '\n\nContent: ' .. v.value or '', }, kind = opts.item_kind, }) diff --git a/lua/cmp-dotenv/option.lua b/lua/cmp-dotenv/option.lua index 8494639..a656216 100644 --- a/lua/cmp-dotenv/option.lua +++ b/lua/cmp-dotenv/option.lua @@ -10,6 +10,7 @@ local defaults = { item_kind = cmp.lsp.CompletionItemKind.Variable, eval_on_confirm = false, show_documentation = true, + show_content_on_docs = true, documentation_kind = 'markdown', dotenv_environment = '.*', -- local,example or .* for any file_priority = function(a, b)