Skip to content

Commit

Permalink
fix: improve logic for JSX detection
Browse files Browse the repository at this point in the history
  • Loading branch information
m-gail committed Feb 23, 2024
1 parent 6e4de04 commit ca03ec5
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lua/typescript-tools/protocol/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,18 @@ end
local function is_completing_jsx(bufnr, position)
local requested_line = vim.api.nvim_buf_get_lines(bufnr, position.line, position.line + 1, false)[1]
local requested_line_until_position = requested_line:sub(1, position.character)
local last_word_before_position = nil

for word in requested_line_until_position:gmatch("%S+") do
last_word_before_position = word
end
local valid_characters_after_start_bracket = "[%w%._$]"

return last_word_before_position ~= nil and last_word_before_position:sub(1, 1) == "<"
for character in requested_line_until_position:reverse():gmatch(".") do
if character == "<" then
return true
end
if not character:match(valid_characters_after_start_bracket) then
return false
end
end
return false
end

---@param position LspPosition
Expand All @@ -265,8 +270,6 @@ local function should_omit_function_snippet_in_context(position, file, request)

local body = coroutine.yield()

print(vim.inspect(body))

return vim.tbl_contains({ "var", "let", "const", "alias" }, body.kind)
end

Expand Down

0 comments on commit ca03ec5

Please sign in to comment.