-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Can now use plugin features from any file with the .curl extension Also contains some bugfixes and refactoring
- Loading branch information
1 parent
7a0ea74
commit 2484e51
Showing
11 changed files
with
275 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
runtime! syntax/sh.vim | ||
|
||
syn match curlFlag "-[a-zA-Z0-9-]\+" | ||
hi def link curlFlag Type | ||
|
||
syn match curlMethod "\v-X (GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS|TRACE|CONNECT)"hs=s+3 | ||
hi def link curlMethod Function | ||
|
||
syn match curlUrl "\v(https?://)[^\s]+" contains=curlProtocol | ||
syn match curlProtocol "\v^(https?://)" contained | ||
hi def link curlUrl String | ||
hi def link curlProtocol Type | ||
|
||
syn match curlCommand "\vcurl" | ||
hi def link curlCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
vim.bo.syntax = "sh" | ||
vim.bo.commentstring = "# %s" | ||
|
||
vim.treesitter.language.register("bash", "curl") | ||
|
||
-- Custom highlights for curl-specific elements | ||
local query = vim.treesitter.query.parse( | ||
"bash", | ||
[[ | ||
;; Highlight the 'curl' command | ||
((command_name) @curl (#eq? @curl "curl")) | ||
;; Highlight curl options | ||
((word) @curl_option (#match? @curl_option "^-")) | ||
;; Highlight HTTP methods | ||
((word) @http_method (#match? @http_method "^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS|TRACE|CONNECT)$")) | ||
;; Highlight URLs | ||
((word) @url (#match? @url "^https?://")) | ||
]] | ||
) | ||
|
||
local bufnr = 0 | ||
local parser = vim.treesitter.get_parser(bufnr, "bash") | ||
local tree = parser:parse()[1] | ||
local root = tree:root() | ||
|
||
for id, node in query:iter_captures(root, bufnr, 0, -1) do | ||
local name = query.captures[id] | ||
local start_row, start_col, end_row, end_col = node:range() | ||
|
||
if name == "curl" then | ||
vim.api.nvim_buf_add_highlight(bufnr, -1, "CurlKeyword", start_row, start_col, end_col) | ||
elseif name == "curl_option" or name == "http_method" then | ||
vim.api.nvim_buf_add_highlight(bufnr, -1, "CurlFunction", start_row, start_col, end_col) | ||
elseif name == "url" then | ||
vim.api.nvim_buf_add_highlight(bufnr, -1, "CurlUrl", start_row, start_col, end_col) | ||
end | ||
end | ||
|
||
vim.api.nvim_set_hl(0, "CurlUrl", { | ||
link = "@text", | ||
}) | ||
|
||
vim.api.nvim_set_hl(0, "CurlFunction", { | ||
link = "@function", | ||
}) | ||
|
||
vim.api.nvim_set_hl(0, "CurlKeyword", { | ||
link = "@operator", | ||
}) | ||
|
||
local config = require("curl.config") | ||
local execute_mapping = config.get("mappings")["execute_curl"] | ||
vim.api.nvim_buf_set_keymap( | ||
0, | ||
"n", | ||
execute_mapping, | ||
"<cmd>lua require('curl.api').execute_curl()<CR>", | ||
{ noremap = true, silent = true } | ||
) | ||
|
||
vim.api.nvim_create_autocmd({ "InsertLeave", "TextChanged" }, { | ||
command = "silent w", | ||
buffer = 0, | ||
nested = true, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.