Skip to content

Commit

Permalink
fix: check if docs is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRibera committed Dec 27, 2023
1 parent 7d368a7 commit 7267fb5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lua/cmp-dotenv/dotenv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function M.as_completion()
docs = 'Content: ' .. v.value
end

if v.docs then
if v.docs ~= nil then
docs = v.docs .. '\n\n' .. docs
end

Expand Down
2 changes: 2 additions & 0 deletions spec/dotenv/.env.local
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Local Documentation
#
# Local Documentation Next Line
VARIABLE=Hello From Local
# Local Test
OTHER_VARIABLE=Other Local Value
Expand Down
15 changes: 12 additions & 3 deletions spec/dotenv_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ describe('Load dotenv workspace', function()
dotenv.load()
local all_env = dotenv.get_all_env()
assert.are.same(3, vim.tbl_count(all_env))
assert.are.same({ value = 'Hello From Local', docs = 'Local Documentation' }, all_env.VARIABLE)
assert.are.same(
{ value = 'Hello From Local', docs = 'Local Documentation\n\nLocal Documentation Next Line' },
all_env.VARIABLE
)
assert.are.same({ value = 'Local Data', docs = nil }, all_env.LOCAL_VAR)
assert.are.same({ value = 'Other Local Value', docs = 'Local Test' }, all_env.OTHER_VARIABLE)
end)
Expand All @@ -39,7 +42,10 @@ describe('Load dotenv workspace', function()
dotenv.load()
local all_env = dotenv.get_all_env()
assert.are.same(3, vim.tbl_count(all_env))
assert.are.same({ value = 'Hello From Local', docs = 'Local Documentation' }, all_env.VARIABLE)
assert.are.same(
{ value = 'Hello From Local', docs = 'Local Documentation\n\nLocal Documentation Next Line' },
all_env.VARIABLE
)
assert.are.same({ value = 'Local Data', docs = nil }, all_env.LOCAL_VAR)
end)

Expand All @@ -65,6 +71,9 @@ describe('Completion dotenv workspace', function()
local variable = tbl_find(all, 'VARIABLE')
assert.are.same('VARIABLE', variable.label)
assert.are.same('VARIABLE', variable.insertText)
assert.are.same('Local Documentation\n\nContent: Hello From Local', variable.documentation.value)
assert.are.same(
'Local Documentation\n\nLocal Documentation Next Line\n\nContent: Hello From Local',
variable.documentation.value
)
end)
end)

0 comments on commit 7267fb5

Please sign in to comment.