Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for highlighting enclosing brackets #2622

Merged
merged 1 commit into from
Sep 20, 2023

Conversation

riverbl
Copy link
Contributor

@riverbl riverbl commented Sep 19, 2023

Highlight enclosing brackets when highlight_matching_brackets is enabled.

Draw lines delineating the enclosing scope when highlight_scope_lines is enabled.

Currently only draws the highlights and scope lines for one cursor, even if there are multiple cursors.

Currently doesn't draw highlights or scope lines on the sticky header.

Relates to #2417.

  • Added an entry to CHANGELOG.md if this change could be valuable to users

@codecov
Copy link

codecov bot commented Sep 19, 2023

Codecov Report

Merging #2622 (715ebd6) into master (4154fe3) will decrease coverage by 0.01%.
Report is 2 commits behind head on master.
The diff coverage is 8.19%.

@@            Coverage Diff             @@
##           master    #2622      +/-   ##
==========================================
- Coverage   11.65%   11.64%   -0.01%     
==========================================
  Files         141      141              
  Lines       43634    44103     +469     
==========================================
+ Hits         5084     5135      +51     
- Misses      38550    38968     +418     
Files Changed Coverage Δ
lapce-app/src/app.rs 0.00% <0.00%> (ø)
lapce-app/src/config.rs 0.00% <0.00%> (ø)
lapce-app/src/config/ui.rs 0.00% <0.00%> (ø)
lapce-app/src/doc.rs 0.00% <0.00%> (ø)
lapce-app/src/editor/view.rs 0.00% <0.00%> (ø)
lapce-core/src/syntax/mod.rs 9.88% <0.00%> (+0.05%) ⬆️
lapce-proxy/src/plugin/catalog.rs 0.00% <0.00%> (ø)
lapce-proxy/src/plugin/lsp.rs 0.00% <0.00%> (ø)
lapce-proxy/src/plugin/mod.rs 0.00% <0.00%> (ø)
lapce-proxy/src/plugin/psp.rs 0.00% <0.00%> (ø)
... and 3 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

// We only need to draw anything if start_line is on or before the visible section and
// end_line is on or after the visible section.
let y0 = start_line_y.or_else(|| {
(start_line < *screen_lines.lines.first().unwrap())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it valid to assume that screen_lines.lines is non-empty and sorted?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's sorted but could be empty I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it to not assume that screen_lines.lines is non-empty.

let end = self.find_matching_pair(start)?;
if end >= offset {
return Some((start, end));
if start < offset {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously the the offset immediately before an opening bracket was considered enclosed (i.e.: |( )). This was inconsistent with WordCursor::find_enclosing_pair, which is used for language unaware bracket search, so I've changed it to not consider that offset to be enclosed.

@@ -428,7 +428,7 @@ impl<'a> WordCursor<'a> {
if matching_pair_direction(c) == Some(true) {
let opening_bracket_offset = self.inner.pos();
if let Some(closing_bracket_offset) = self.match_pairs() {
if (opening_bracket_offset..closing_bracket_offset)
if (opening_bracket_offset..=closing_bracket_offset)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a bug where the offset immediately before the closing bracket (i.e.: ( |)) was not considered enclosed.

Highlight enclosing brackets when `highlight_matching_brackets` is enabled.

Draw lines delineating the enclosing scope when `highlight_scope_lines` is enabled.
@dzhou121 dzhou121 merged commit c539f7a into lapce:master Sep 20, 2023
8 of 10 checks passed
@panekj panekj added this to the Next release milestone Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants