Comments (6)
We should find a way to add that, I'll take a look eventually, PR welcome.
from nvim-treesitter-context.
adding else
to the default patterns accomplishes this.
patterns = { -- Match patterns for TS nodes. These get wrapped to match at word boundaries.
-- For all filetypes
-- Note that setting an entry here replaces all other patterns for this entry.
-- By setting the 'default' entry below, you can control which nodes you want to
-- appear in the context window.
default = {
'class',
'function',
'method',
'for',
'while',
'if',
'switch',
'case',
'else'
},
from nvim-treesitter-context.
adding
else
to the default patterns accomplishes this.
This works for Python but does not work for C++, because Python has an else_clause
node, but in C++, it's just an expression_statement
.
from nvim-treesitter-context.
C++:
if (1) 1;
else if (2) 2;
else 3;
translation_unit [0, 0] - [3, 0]
if_statement [0, 0] - [2, 7]
condition: condition_clause [0, 3] - [0, 6]
value: number_literal [0, 4] - [0, 5]
consequence: expression_statement [0, 7] - [0, 9]
number_literal [0, 7] - [0, 8]
alternative: if_statement [1, 5] - [2, 7]
condition: condition_clause [1, 8] - [1, 11]
value: number_literal [1, 9] - [1, 10]
consequence: expression_statement [1, 12] - [1, 14]
number_literal [1, 12] - [1, 13]
alternative: expression_statement [2, 5] - [2, 7]
number_literal [2, 5] - [2, 6]
Python:
if 1:
1
elif 2:
2
else:
3
module [0, 0] - [6, 0]
if_statement [0, 0] - [5, 2]
condition: integer [0, 3] - [0, 4]
consequence: block [1, 1] - [1, 2]
expression_statement [1, 1] - [1, 2]
integer [1, 1] - [1, 2]
alternative: elif_clause [2, 0] - [3, 2]
condition: integer [2, 5] - [2, 6]
consequence: block [3, 1] - [3, 2]
expression_statement [3, 1] - [3, 2]
integer [3, 1] - [3, 2]
alternative: else_clause [4, 0] - [5, 2]
body: block [5, 1] - [5, 2]
expression_statement [5, 1] - [5, 2]
integer [5, 1] - [5, 2]
JavaScript's if else
is similar to C++'s, but there's an else_clause
in JavaScript:
if (1) 1;
else if (2) 2;
else 3;
program [0, 0] - [3, 0]
if_statement [0, 0] - [2, 7]
condition: parenthesized_expression [0, 3] - [0, 6]
number [0, 4] - [0, 5]
consequence: expression_statement [0, 7] - [0, 9]
number [0, 7] - [0, 8]
alternative: else_clause [1, 0] - [2, 7]
if_statement [1, 5] - [2, 7]
condition: parenthesized_expression [1, 8] - [1, 11]
number [1, 9] - [1, 10]
consequence: expression_statement [1, 12] - [1, 14]
number [1, 12] - [1, 13]
alternative: else_clause [2, 0] - [2, 7]
expression_statement [2, 5] - [2, 7]
number [2, 5] - [2, 6]
from nvim-treesitter-context.
Issue is now stale due to #198
from nvim-treesitter-context.
So should this work now for all supported languages now? I checked with C++ and the else
still isn't displayed as context
from nvim-treesitter-context.
Related Issues (20)
- Context has no highlighting when first opening Neovim HOT 4
- Add `trim_scope = "center"` HOT 1
- The `stl` setting from `'fillchars'` is being displayed in ts-context when using `'statuscolumn'` HOT 3
- context.lua:17: attempt to index local 'tree' (a nil value) HOT 3
- Context header disappears with markdown_inline parser installed HOT 1
- Disbled languages config option HOT 1
- feat: Lua API to get the status of treesitter context
- Very poor performance after “do not use vim.treesitter.highlighter” HOT 2
- Use one floating window instead of two. HOT 10
- Multi-line function definition is not handled HOT 1
- Feature Request: Formalise require('treesitter-context.context').get() API HOT 2
- Feat: tag the ts-context windows so they can be identified programmatically HOT 2
- Can this plugin be configured such that scrolloff is respected between the context and the cursor? HOT 2
- Show ruby blocks in context HOT 3
- Julia context queries not updated HOT 10
- height key must be positive integer error while scrolling down in markdown file when the first line is empty HOT 6
- Q: is there a way to replicate GitHub's context? HOT 4
- Error message when opening the command line window with q: HOT 2
- invaild node type in haskell HOT 1
- Unable to load context query for c_sharp 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 nvim-treesitter-context.