aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CONTRIBUTING.md15
-rw-r--r--README.md1
-rw-r--r--doc/nvim-treesitter.txt36
-rw-r--r--lua/nvim-treesitter/highlight.lua9
-rw-r--r--lua/nvim-treesitter/parsers.lua7
-rw-r--r--plugin/nvim-treesitter.vim8
-rw-r--r--queries/rst/highlights.scm81
-rw-r--r--queries/rst/locals.scm31
-rw-r--r--queries/rst/textobjects.scm2
9 files changed, 186 insertions, 4 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 8091c6203..cae75f0e4 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -122,6 +122,21 @@ are optional and will not have any effect for now.
builtin
@structure
```
+
+#### Text
+
+Mainly for markup languages.
+
+```
+@text
+@text.strong
+@text.emphasis
+@text.underline
+@text.title
+@text.literal
+@text.uri
+```
+
### Locals
```
@definition for various definitions
diff --git a/README.md b/README.md
index 1f63f3ee6..01d498602 100644
--- a/README.md
+++ b/README.md
@@ -284,6 +284,7 @@ List of currently supported languages:
- [x] regex (maintained by @theHamsta)
- [ ] jsdoc
- [x] dart (maintained by @Akin909)
+- [x] rst (maintained by @stsewd)
## User Query Extensions
diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt
index 3b08e662b..82a6539b3 100644
--- a/doc/nvim-treesitter.txt
+++ b/doc/nvim-treesitter.txt
@@ -1,4 +1,4 @@
-*nvim-treesitter*
+*nvim-treesitter*
Minimum version of neovim: nightly
@@ -35,7 +35,7 @@ By default, everything is disabled. To enable support for features, in your `ini
disable = { 'c', 'rust' }, -- list of language that will be disabled
custom_captures = { -- mapping of user defined captures to highlight groups
-- ["foo.bar"] = "Identifier" -- highlight own capture @foo.bar with highlight group "Identifier", see :h nvim-treesitter-query-extensions
- },
+ },
},
incremental_selection = {
enable = true,
@@ -165,7 +165,7 @@ get_node_text(node, bufnr) *ts_utils.get_node_text*
return the text content of a node
is_parent(dest, source) *ts_utils.is_parent*
- determines wether `dest` is a parent of `source`
+ determines wether `dest` is a parent of `source`
return a boolean
get_named_children(node) *ts_utils.get_named_children*
@@ -176,7 +176,7 @@ get_next_node(node, allow_switch_parent, allow_next_parent) *ts_utils.get_next_n
if no node is found, returns `nil`.
if `allow_switch_parent` is true, it will allow switching parent
when the node is the last node
- if `allow_next_parent` is true, it will allow next parent if
+ if `allow_next_parent` is true, it will allow next parent if
the node is the last node and the next parent doesn't have children.
get_previous_node(node, allow_switch_parents, allow_prev_parent) *ts_utils.get_previous_node*
@@ -361,4 +361,32 @@ This is left as an exercise for the reader.
For includes: `#include` in C, `use` or `extern crate` in Rust, or `require`
in Lua
+`TSText`
+ *hl-TSText*
+For strings considered text in a markup language.
+
+`TSStrong`
+ *hl-TSStrong*
+For text to be represented with strong.
+
+`TSEmphasis`
+ *hl-TSEmphasis*
+For text to be represented with emphasis.
+
+`TSUnderline`
+ *hl-TSUnderline*
+For text to be represented with an underline.
+
+`TSTitle`
+
+Text that is part of a title.
+
+`TSLiteral`
+ *hl-TSLiteral*
+Literal text.
+
+`TSURI`
+ *hl-TSURI*
+Any URI like a link or email.
+
vim:tw=78:ts=8:noet:ft=help:norl:
diff --git a/lua/nvim-treesitter/highlight.lua b/lua/nvim-treesitter/highlight.lua
index a56b0d7a9..6058d52c6 100644
--- a/lua/nvim-treesitter/highlight.lua
+++ b/lua/nvim-treesitter/highlight.lua
@@ -53,6 +53,15 @@ hlmap["type.builtin"] = "TSTypeBuiltin"
hlmap["structure"] = "TSStructure"
hlmap["include"] = "TSInclude"
+-- Text
+hlmap["text"] = "TSText"
+hlmap["text.strong"] = "TSStrong"
+hlmap["text.emphasis"] = "TSEmphasis"
+hlmap["text.underline"] = "TSUnderline"
+hlmap["text.title"] = "TSTitle"
+hlmap["text.literal"] = "TSLiteral"
+hlmap["text.uri"] = "TSURI"
+
function M.attach(bufnr, lang)
local bufnr = bufnr or api.nvim_get_current_buf()
local lang = lang or parsers.get_buf_lang(bufnr)
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua
index 9ee71bc8a..1662629ed 100644
--- a/lua/nvim-treesitter/parsers.lua
+++ b/lua/nvim-treesitter/parsers.lua
@@ -214,6 +214,13 @@ list.dart = {
}
}
+list.rst = {
+ install_info = {
+ url = "https://github.com/stsewd/tree-sitter-rst",
+ files = { "src/parser.c", "src/scanner.c" },
+ }
+}
+
-- Parsers for injections
list.regex = {
install_info = {
diff --git a/plugin/nvim-treesitter.vim b/plugin/nvim-treesitter.vim
index 87ff6634a..8486f12bd 100644
--- a/plugin/nvim-treesitter.vim
+++ b/plugin/nvim-treesitter.vim
@@ -62,3 +62,11 @@ highlight default link TSDefinitionUsage Visual
highlight default link TSDefinition Search
highlight default link TSCurrentScope CursorLine
+
+highlight default link TSText Normal
+highlight default TSStrong term=bold cterm=bold gui=bold
+highlight default TSEmphasis term=italic cterm=italic gui=italic
+highlight default TSUnderline term=underline cterm=underline gui=underline
+highlight default link TSTitle Title
+highlight default link TSLiteral String
+highlight default link TSURI Identifier
diff --git a/queries/rst/highlights.scm b/queries/rst/highlights.scm
new file mode 100644
index 000000000..477ede2ca
--- /dev/null
+++ b/queries/rst/highlights.scm
@@ -0,0 +1,81 @@
+; Marks
+
+[
+ ".."
+ "|"
+ "--"
+ "__"
+ "::"
+ "bullet"
+ "adornment"
+ (transition)
+] @punctuation.special
+
+; Directives
+
+(directive
+ name: (type) @function)
+
+((directive
+ name: (type) @include)
+ (#match? @include "^include::$"))
+
+; Blocks
+
+[
+ (literal_block)
+ (line_block)
+ (block_quote)
+ (doctest_block)
+] @text.literal
+
+(substitution_definition
+ name: (substitution) @constant)
+
+(footnote
+ name: (label) @constant)
+
+(citation
+ name: (label) @constant)
+
+(target
+ name: (reference)? @constant
+ link: (_) @text.literal)
+
+; Inline markup
+
+(emphasis) @text.emphasis
+
+(strong) @text.strong
+
+(standalone_hyperlink) @text.uri
+
+[
+ (interpreted_text)
+ (literal)
+] @text.literal
+
+[
+ (target)
+ (substitution_reference)
+ (footnote_reference)
+ (citation_reference)
+ (reference)
+] @constant
+
+; Embedded
+
+(doctest_block) @embed
+(directive
+ body: (body) @embed)
+
+; Others
+
+(title) @text.title
+
+(attribution) @text.emphasis
+
+(comment) @comment
+(comment "..") @comment
+
+(ERROR) @error
diff --git a/queries/rst/locals.scm b/queries/rst/locals.scm
new file mode 100644
index 000000000..4838935b4
--- /dev/null
+++ b/queries/rst/locals.scm
@@ -0,0 +1,31 @@
+;; Scopes
+
+(document) @scope
+
+(directive) @scope
+
+;; Definitions
+
+(substitution_definition
+ name: (substitution) @definition)
+
+(footnote
+ name: (label) @definition)
+
+(citation
+ name: (label) @definition)
+
+(target
+ name: (reference) @definition)
+
+; Inline targets
+(target) @definition
+
+;; References
+
+[
+ (substitution_reference)
+ (footnote_reference)
+ (citation_reference)
+ (reference)
+] @reference
diff --git a/queries/rst/textobjects.scm b/queries/rst/textobjects.scm
new file mode 100644
index 000000000..baeadc938
--- /dev/null
+++ b/queries/rst/textobjects.scm
@@ -0,0 +1,2 @@
+(directive
+ body: (body) @function.inner) @function.outer