Debian Codegraph @

runtime/queries/go/injections.scm

raw symbols SCIP
1 ((comment) @injection.content
2 (#set! injection.language "comment"))
3
4 ; Inject markdown into documentation comments
5 ;
6 ; Go's comments are documentation comments when they are directly followed
7 ; by one of Go's statements (e.g. `type`, `func`, `const`)
8 ;
9 ; This is only a partial implementation, which covers only
10 ; block comments. For line comments (which are more common),
11 ; upstream changes to the grammar are required.
12 (source_file
13 (comment) @injection.content . (comment)* . [
14 (package_clause) ; `package`
15 (type_declaration) ; `type`
16 (function_declaration) ; `func`
17 (method_declaration) ; `func`
18 (var_declaration) ; `var`
19 (const_declaration) ; `const`
20 ; var (
21 ; A = 1
22 ; B = 2
23 ; )
24 (var_spec)
25 ; const (
26 ; A = 1
27 ; B = 2
28 ; )
29 (const_spec)
30 ]
31 (#set! injection.language "markdown"))
32
33 ((comment) @injection.content
34 (#match? @injection.content "^//go:generate")
35 (#set! injection.language "bash"))
36
37 (call_expression
38 (selector_expression) @_function
39 (#any-of? @_function "regexp.Match" "regexp.MatchReader" "regexp.MatchString" "regexp.Compile" "regexp.CompilePOSIX" "regexp.MustCompile" "regexp.MustCompilePOSIX")
40 (argument_list
41 .
42 [
43 (raw_string_literal (raw_string_literal_content) @injection.content)
44 (interpreted_string_literal (interpreted_string_literal_content) @injection.content)
45 ]
46 (#set! injection.language "regex")))
47
48 ; https://pkg.go.dev/fmt#Printf
49 ; https://pkg.go.dev/fmt#Sprintf
50 ; https://pkg.go.dev/fmt#Scanf
51 ; https://pkg.go.dev/fmt#Errorf
52 ((call_expression
53 function: (selector_expression
54 operand: (identifier) @_module
55 field: (field_identifier) @_func)
56 arguments: (argument_list
57 . (interpreted_string_literal) @injection.content))
58 (#eq? @_module "fmt")
59 (#any-of? @_func "Printf" "Sprintf" "Scanf" "Errorf")
60 (#set! injection.language "go-format-string"))
61
62 ; https://pkg.go.dev/fmt#Fprintf
63 ; https://pkg.go.dev/fmt#Fscanf
64 ; https://pkg.go.dev/fmt#Sscanf
65 ((call_expression
66 function: (selector_expression
67 operand: (identifier) @_module
68 field: (field_identifier) @_func)
69 arguments: (argument_list
70 ; [(identifier) (interpreted_string_literal)]
71 (_)
72 ; (identifier)
73 .
74 (interpreted_string_literal) @injection.content))
75 (#eq? @_module "fmt")
76 (#any-of? @_func "Fprintf" "Fscanf" "Sscanf")
77 (#set! injection.language "go-format-string"))
78
79 ; https://pkg.go.dev/log#Printf
80 ; https://pkg.go.dev/log#Fatalf
81 ; https://pkg.go.dev/log#Panicf
82 ; https://pkg.go.dev/log#Logger.Printf
83 ; https://pkg.go.dev/log#Logger.Fatalf
84 ; https://pkg.go.dev/log#Logger.Panicf
85 ((call_expression
86 function: (selector_expression
87 operand: (identifier)
88 field: (field_identifier) @_func)
89 arguments: (argument_list
90 . (interpreted_string_literal) @injection.content))
91 (#any-of? @_func "Printf" "Fatalf" "Panicf")
92 (#set! injection.language "go-format-string"))