Skip to content

Commit

Permalink
Merge pull request #968 from savetheclocktower/tree-sitter-april
Browse files Browse the repository at this point in the history
Tree-sitter fixes (1.116 edition)
  • Loading branch information
savetheclocktower authored Apr 14, 2024
2 parents 35dd1cc + 5d6af88 commit 41d8915
Show file tree
Hide file tree
Showing 25 changed files with 385 additions and 425 deletions.
10 changes: 10 additions & 0 deletions packages/language-gfm/grammars/modern-tree-sitter-gfm-inline.cson
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
scopeName: 'source.gfm.inline'
type: 'modern-tree-sitter'
parser: 'tree-sitter-markdown_inline'

injectionRegex: '^(markdown-inline-internal)$'

treeSitter:
parserSource: 'github:MDeiml/tree-sitter-markdown/tree-sitter-markdown-inline#28aa3baef73bd458d053b613b8bd10fd102b4405'
grammar: 'tree-sitter-markdown-inline/tree-sitter-markdown-inline.wasm'
highlightsQuery: 'tree-sitter-markdown-inline/highlights.scm'

This file was deleted.

15 changes: 8 additions & 7 deletions packages/language-gfm/grammars/modern-tree-sitter-gfm.cson
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# This grammar doesn't have its own name because it's only meant to be injected.
scopeName: 'source.gfm.embedded'
scopeName: 'source.gfm'
type: 'modern-tree-sitter'
name: 'GitHub Markdown'
parser: 'tree-sitter-markdown'

injectionRegex: '(MARKDOWN|markdown|GFM|gfm)$'
injectionRegex: '^(markdown|MARKDOWN|gfm|GFM)$'

treeSitter:
grammar: 'tree-sitter/tree-sitter-markdown.wasm'
highlightsQuery: 'tree-sitter/tree-sitter-markdown/highlights.scm'
foldsQuery: 'tree-sitter/tree-sitter-markdown/folds.scm'
tagsQuery: 'tree-sitter/tree-sitter-markdown/tags.scm'
parserSource: 'github:MDeiml/tree-sitter-markdown/tree-sitter-markdown#28aa3baef73bd458d053b613b8bd10fd102b4405'
grammar: 'tree-sitter-markdown/tree-sitter-markdown.wasm'
highlightsQuery: 'tree-sitter-markdown/highlights.scm'
foldsQuery: 'tree-sitter-markdown/folds.scm'
tagsQuery: 'tree-sitter-markdown/tags.scm'

fileTypes: [
'markdown'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
; BOLD/ITALIC/OTHER
; ===============

(emphasis) @markup.italic.gfm

(emphasis
. (emphasis_delimiter) @punctuation.definition.emphasis.begin.gfm)

(emphasis
(emphasis_delimiter) @punctuation.definition.emphasis.end.gfm .)

(strong_emphasis) @markup.bold.gfm
((strong_emphasis) @punctuation.definition.emphasis.begin.gfm
(#set! adjust.endAfterFirstMatchOf "^\\*\\*"))
((strong_emphasis) @punctuation.definition.emphasis.end.gfm
(#set! adjust.startBeforeFirstMatchOf "\\*\\*$"))

(strikethrough) @markup.strike.gfm

((strikethrough) @punctuation.definition.strike.begin.gfm
(#set! adjust.endAfterFirstMatchOf "^~~"))
((strikethrough) @punctuation.definition.strike.end.gfm
(#set! adjust.startBeforeFirstMatchOf "~~$"))


; INLINE/REPLACED
; ===============

((uri_autolink) @markup.underline.link
(#set! adjust.startAfterFirstMatchOf "^<")
(#set! adjust.endBeforeFirstMatchOf ">$"))

((uri_autolink) @punctuation.definition.begin.uri-autolink.gfm
(#set! adjust.endAfterFirstMatchOf "^<"))

((uri_autolink) @punctuation.definition.end.uri-autolink.gfm
(#set! adjust.startBeforeFirstMatchOf ">$"))

((link_text (image (image_description))) @_IGNORE_
(#set! capture.final))

[(link_text) (image_description)] @string.unquoted.gfm @meta.link.text

; The text inside []s in anchors/image syntax.
(full_reference_link
(link_label) @markup.underline.link.gfm
(#set! adjust.startAfterFirstMatchOf "^\\[")
(#set! adjust.endBeforeFirstMatchOf "]$"))

(image
(link_destination) @markup.underline.link.gfm)

(inline_link
(link_destination) @markup.underline.link.gfm)

(link_title) @string.quoted.link-title.gfm


; CODE SPANS
; ==========

(code_span) @meta.embedded.line.inline-code.gfm @markup.raw.inline.gfm

(code_span
. (code_span_delimiter) @punctuation.definition.begin.string.inline-code.gfm)

(code_span
(code_span_delimiter) @punctuation.definition.end.string.inline-code.gfm
.)


; MISC
; ====

(backslash_escape) @constant.character.escape.gfm

(numeric_character_reference) @constant.character.entity.gfm
Binary file not shown.
11 changes: 11 additions & 0 deletions packages/language-gfm/grammars/tree-sitter-markdown/folds.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

; Each individual list item can be folded if it's hard-wrapped.
((list_item) @fold
(#set! fold.endAt endPosition)
(#set! fold.adjustToEndOfPreviousRow true))

; Each section represents a heading and all the content underneath it until the
; next heading of equivalent or higher importance.
((section) @fold
(#set! fold.endAt endPosition)
(#set! fold.adjustToEndOfPreviousRow true))
94 changes: 94 additions & 0 deletions packages/language-gfm/grammars/tree-sitter-markdown/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
; HEADINGS
; ========

(setext_heading
heading_content: (_) @markup.heading.heading-1.gfm
(setext_h1_underline) @punctuation.definition.heading-underline.gfm)

(setext_heading
heading_content: (_) @markup.heading.heading-2.gfm
(setext_h2_underline) @punctuation.definition.heading-underline.gfm)

(atx_heading
(atx_h1_marker)) @markup.heading.heading-1.gfm

(atx_heading
(atx_h2_marker)) @markup.heading.heading-2.gfm

(atx_heading
(atx_h3_marker)) @markup.heading.heading-3.gfm

(atx_heading
(atx_h4_marker)) @markup.heading.heading-4.gfm

(atx_heading
(atx_h5_marker)) @markup.heading.heading-5.gfm

(atx_heading
(atx_h6_marker)) @markup.heading.heading-6.gfm


; SECTIONS
; ========

(paragraph) @markup.paragraph.gfm
(thematic_break) @markup.horizontal-rule.gfm

(block_quote) @markup.quote.blockquote.gfm
((block_quote_marker) @punctuation.definition.blockquote.gfm
(#set! adjust.startAndEndAroundFirstMatchOf "\\S"))


; LISTS
; =====

(list) @meta.list.gfm

(list_item
(list_marker_dot) @punctuation.definition.list-item.gfm
) @markup.list.numbered

(list_item
[
(list_marker_star)
(list_marker_minus)
(list_marker_plus)
] @punctuation.definition.list-item.gfm
) @markup.list.unnumbered

(task_list_marker_unchecked) @punctuation.definition.task-marker.unchecked.gfm
(task_list_marker_checked) @punctuation.definition.task-marker.unchecked.gfm

; CODE BLOCKS
; ===========

(info_string) @storage.modifier.language._TEXT_.gfm

(fenced_code_block
(code_fence_content) @markup.raw.block.fenced.gfm) @meta.embedded.block.fenced-code.gfm
(indented_code_block) @markup.raw.block.indented.gfm @meta.embedded.block.indented-code.gfm


; MISC
; ====

(pipe_table) @markup.other.table.gfm
(pipe_table_header
(pipe_table_cell) @markup.other.table-cell.header.gfm)
(pipe_table_row
(pipe_table_cell) @markup.other.table-cell.data.gfm)
(pipe_table_delimiter_row
(pipe_table_delimiter_cell
(_) @punctuation.separator.table-row.gfm)
)


; Link definitions

(link_reference_definition
(link_label)
(link_destination) @markup.underline.link.gfm)

((link_label) @meta.link.text
(#set! adjust.offsetStart 1)
(#set! adjust.offsetEnd -1))
52 changes: 52 additions & 0 deletions packages/language-gfm/grammars/tree-sitter-markdown/tags.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

; Each heading counts as a tag for symbol navigation purposes. We'll indicate a
; symbol's heading level with a certain number of dots prepended to the symbol
; name.

((atx_heading
(atx_h1_marker)
heading_content: (_) @name) @definition.heading
(#set! symbol.strip "(^\\s*|\\s*$)")
(#set! symbol.prepend "· "))

((atx_heading
(atx_h2_marker)
heading_content: (_) @name) @definition.heading
(#set! symbol.strip "(^\\s*|\\s*$)")
(#set! symbol.prepend "·· "))

((atx_heading
(atx_h3_marker)
heading_content: (_) @name) @definition.heading
(#set! symbol.strip "(^\\s*|\\s*$)")
(#set! symbol.prepend "··· "))

((atx_heading
(atx_h4_marker)
heading_content: (_) @name) @definition.heading
(#set! symbol.strip "(^\\s*|\\s*$)")
(#set! symbol.prepend "···· "))

((atx_heading
(atx_h5_marker)
heading_content: (_) @name) @definition.heading
(#set! symbol.strip "(^\\s*|\\s*$)")
(#set! symbol.prepend "····· "))

((atx_heading
(atx_h6_marker)
heading_content: (_) @name) @definition.heading
(#set! symbol.strip "(^\\s*|\\s*$)")
(#set! symbol.prepend "······ "))

((setext_heading
heading_content: (_) @name) @definition.heading
(setext_h1_underline)
(#set! symbol.strip "(^\\s*|\\s*$)")
(#set! symbol.prepend "· "))

((setext_heading
heading_content: (_) @name) @definition.heading
(setext_h2_underline)
(#set! symbol.strip "(^\\s*|\\s*$)")
(#set! symbol.prepend "·· "))
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Loading

0 comments on commit 41d8915

Please sign in to comment.