feat: plugin code, updates

This commit is contained in:
2025-09-07 23:36:04 +03:00
parent 773f82e610
commit 4188c9221f
15 changed files with 354 additions and 11 deletions

View File

@@ -0,0 +1,25 @@
; Quote pairs
("'" @open "'" @close)
("\"" @open "\"" @close)
; Command substitution
("$(" @open ")" @close)
("${" @open "}" @close)
; Parentheses
("(" @open ")" @close)
; Square brackets
("[" @open "]" @close)
; Curly braces
("{" @open "}" @close)
; ShellSpec block structure (if using End keyword)
(simple_command
(command_name) @_cmd
(#match? @_cmd "^(Describe|Context|It|Specify|Example)$")) @open
(simple_command
(command_name) @_end
(#eq? @_end "End")) @close

View File

@@ -0,0 +1,29 @@
name = "ShellSpec"
grammar = "bash"
path_suffixes = ["_spec.sh", ".spec.sh"]
line_comments = ["# "]
tab_size = 2
hard_tabs = false
first_line_pattern = "^#!/.*shellspec"
[[brackets]]
start = "'"
end = "'"
close = true
newline = false
not_in = ["string", "comment"]
[[brackets]]
start = "\""
end = "\""
close = true
newline = false
not_in = ["string", "comment"]
[[brackets]]
start = "$("
end = ")"
close = true
newline = true
block_comment = { start = ": '", end = "'" }

View File

@@ -0,0 +1,73 @@
; BDD Structure Keywords
["Describe" "Context" "ExampleGroup"] @keyword.function
["It" "Specify" "Example"] @keyword.function
["Todo"] @keyword.function
; Prefixed block keywords
["xDescribe" "xContext" "xExampleGroup" "xIt" "xSpecify" "xExample"] @keyword.function.inactive
["fDescribe" "fContext" "fExampleGroup" "fIt" "fSpecify" "fExample"] @keyword.function.focus
; Control flow
["Pending" "Skip"] @keyword.control
["When" "The" "Assert"] @keyword.control
["End"] @keyword.control
; Hook keywords
["BeforeEach" "AfterEach" "BeforeAll" "AfterAll"] @keyword.function
["BeforeCall" "AfterCall" "BeforeRun" "AfterRun"] @keyword.function
["Before" "After"] @keyword.function
; Helper keywords
["Include" "Set" "Data" "Parameters" "Dump"] @keyword
["Path" "File" "Dir"] @keyword
; Evaluation keywords
["call" "run" "command" "script" "source"] @function.method
; Assertion keywords
["should" "not"] @keyword.operator
["output" "stdout" "error" "stderr" "status" "variable" "path"] @variable.builtin
; Matchers
["equal" "eq" "be" "exist" "valid" "satisfy"] @function.method
["match" "start_with" "end_with" "include" "contain"] @function.method
; Modifiers
["line" "word" "length" "contents" "result"] @variable.parameter
["first" "second" "third" "of"] @variable.parameter
; Language chains
["a" "an" "as" "the"] @keyword.operator
; Skip conditional
(word) @keyword.control
(#match? @keyword.control "^Skip\\s+if$")
; Test descriptions and strings
(string) @string
(raw_string) @string
; Comments
(comment) @comment
; Numbers
(number) @number
; Variables
(variable_name) @variable
(variable_assignment) @variable
; Function definitions
(function_definition
name: (word) @function)
; Command names
(command_name) @function
; Data block markers
(word) @punctuation.special
(#eq? @punctuation.special "#|")
; Tags (key:value pairs)
(word) @label
(#match? @label "\\w+:\\w+")

View File

@@ -0,0 +1,38 @@
; Indent content inside BDD blocks
(simple_command
(command_name) @_name
(#match? @_name "^(Describe|Context|ExampleGroup|It|Specify|Example)$")) @indent
; Indent prefixed blocks
(simple_command
(command_name) @_name
(#match? @_name "^[xf](Describe|Context|ExampleGroup|It|Specify|Example)$")) @indent
; Indent hook content
(simple_command
(command_name) @_name
(#match? @_name "^(BeforeEach|AfterEach|BeforeAll|AfterAll|BeforeCall|AfterCall|BeforeRun|AfterRun)$")) @indent
; Indent Data blocks
(simple_command
(command_name) @_name
(#match? @_name "^(Data|Parameters)$")) @indent
; Indent function definitions
(function_definition) @indent
; Indent compound statements
(compound_statement) @indent
; Indent conditional statements
(if_statement) @indent
(for_statement) @indent
(while_statement) @indent
; Indent pipeline continuations
(pipeline) @indent
; Dedent End keyword
(simple_command
(command_name) @_name
(#eq? @_name "End")) @dedent

View File

@@ -0,0 +1,40 @@
; Inject shell highlighting in function definitions
(function_definition
body: (compound_statement) @injection.content
(#set! injection.language "bash"))
; Inject shell in command substitutions
(command_substitution
"$(" @injection.punctuation.bracket
(_) @injection.content
(#set! injection.language "bash")
")" @injection.punctuation.bracket)
; Inject shell in When blocks with call/run
(simple_command
(command_name) @_when
(#eq? @_when "When")
(word) @_action
(#match? @_action "^(call|run)$")
(word)+ @injection.content
(#set! injection.language "bash"))
; Inject shell in arithmetic expressions
(arithmetic_expansion
"$((" @injection.punctuation.bracket
(_) @injection.content
(#set! injection.language "bash")
"))" @injection.punctuation.bracket)
; Inject shell in process substitution
(process_substitution
"<(" @injection.punctuation.bracket
(_) @injection.content
(#set! injection.language "bash")
")" @injection.punctuation.bracket)
(process_substitution
">(" @injection.punctuation.bracket
(_) @injection.content
(#set! injection.language "bash")
")" @injection.punctuation.bracket)

View File

@@ -0,0 +1,33 @@
; Test suites
(simple_command
(command_name) @_name
(#match? @_name "^(Describe|Context|ExampleGroup)$")
(word) @name) @item
; Individual tests
(simple_command
(command_name) @_name
(#match? @_name "^(It|Specify|Example)$")
(word) @name) @item
; Focused tests
(simple_command
(command_name) @_name
(#match? @_name "^f(Describe|Context|It|Specify|Example)$")
(word) @name) @item
; Skipped tests
(simple_command
(command_name) @_name
(#match? @_name "^x(Describe|Context|It|Specify|Example)$")
(word) @name) @item
; Hooks
(simple_command
(command_name) @_name
(#match? @_name "^(BeforeEach|AfterEach|BeforeAll|AfterAll)$")
(word) @name) @item
; Function definitions
(function_definition
name: (word) @name) @item

View File

@@ -0,0 +1,29 @@
; Individual test execution
(simple_command
(command_name) @_name
(#match? @_name "^(It|Specify|Example)$")
(word) @run) @shellspec-test
; Test suite execution
(simple_command
(command_name) @_name
(#match? @_name "^(Describe|Context|ExampleGroup)$")
(word) @run) @shellspec-suite
; Focused test execution
(simple_command
(command_name) @_name
(#match? @_name "^f(It|Specify|Example)$")
(word) @run) @shellspec-focused-test
; Focused suite execution
(simple_command
(command_name) @_name
(#match? @_name "^f(Describe|Context|ExampleGroup)$")
(word) @run) @shellspec-focused-suite
; Pending test markers
(simple_command
(command_name) @_name
(#match? @_name "^(Pending|Todo)$")
(word) @run) @shellspec-pending