Comments (5)
The idea is great. Actually this is my initial plan but I personally did not find sufficient docs or demos for that.
from telescope-heading.nvim.
I'm also really new to TreeSitter but I'm glad to hear your are open to the idea π
I've found the official Neovim TreeSitter playground repository very helpful. (It says you need nightly Neovim, but I only have 0.6 and it works fine for me so far.)
After installing the plugin you can run :TSPlaygroundToggle
to show the abstract syntax tree (AST) in a side view.
I've attached a screenshot of what the AST looks like for an example MarkDown document.
When you hover over the nodes in the tree, the corresponding part of the document is highlighted.
As to queries, when you hit o
while you are in the AST view, you open a third window in which you can edit your own queries. A very basic one I've tried is (atx_heading) @capture
which highlights all headings (h1, h2, etc.) in the document. Note: To highlight them in the document you have to move your cursor on the the @capture
part of the query.
Other plugins that I know of that use TreeSitter are this refactoring plugin, and this tabout one. So I guess we could look there for some inspiration.
from telescope-heading.nvim.
@maxRN https://www.reddit.com/r/neovim/comments/kx1ceh/need_a_little_help_with_tree_sitter_query_matching/ I found this guide, which is basically the scenario we need. I would dive into this recently.
And now, tree-sitter only supports markdown and rst, not capable for every format. This is a cons.
from telescope-heading.nvim.
local function ts_get_headings(filepath)
local headings = {}
local query = [[
(atx_heading) @heading
]]
local parsed_query = ts.parse_query('markdown', query)
local bufnr = vim.api.nvim_get_current_buf() or 0
local parser = ts.get_parser(bufnr, 'markdown')
local root = parser:parse()[1]:root()
local start_row, _, end_row, _ = root:range()
for _id, node in parsed_query:iter_captures(root, bufnr, start_row, end_row) do
local row, _ = node:range()
local line = vim.fn.getline(row + 1)
table.insert(headings, {
heading = vim.trim(line),
line = row,
path = filepath,
})
end
return headings
end
I think this works good. All I have to finish this feature is to add an option to use tree sitter and some checks.
from telescope-heading.nvim.
@maxRN Treesitter parsing for markdown is merged. You may try it. Thanks for your idea.
from telescope-heading.nvim.
Related Issues (11)
- Option for preview HOT 3
- Support for vim help file HOT 2
- Feature request: Support for custom filetypes using header characters (or just .vimrc / init.vim) HOT 7
- Vim help headings donβt show HOT 3
- Help treesitter parser has changed HOT 5
- Is there a way to not sort the headings? HOT 7
- feat: better preview with the heading line at the top of the window HOT 2
- Support Markdown Pandoc filetype HOT 1
- Telescope deprecation warning
- Possibility to support LaTeX tex files HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from telescope-heading.nvim.