fix: Fixes incorrect highlighting for comments at the start of a file (#64235)

The problem was that we were incorrectly not doing
a "stack push" operation when encountering a comment,
but we were doing a pop which triggered a change in the
source range for the next source range (this is done to
avoid overlap between the current occurrence and the
subsequent occurrence that will be emitted).

This is fixed by not ignoring comment markers. As a consequence, we will
emit a few more occurrences than earlier, but I don't think it should be a
big problem in practice. We can also fuse these if needed.
This commit is contained in:
Varun Gandhi 2024-08-05 20:58:56 +08:00 committed by GitHub
parent d19aa106f9
commit e5fdb5c3fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 97 additions and 38 deletions

View File

@ -74,7 +74,8 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
{
// ^ PunctuationBracket punctuation.section.block.begin.java
//lambda expression
// ^^^^^^^^^^^^^^^^^^^ Comment comment.line.double-slash.java
// ^^ Comment punctuation.definition.comment.java
// ^^^^^^^^^^^^^^^^^ Comment comment.line.double-slash.java
MyInterface fobj = (int x, int y)->System.out.println(x+y);
// ^^^^^^^^^^^ IdentifierType support.class.java
// ^ IdentifierOperator keyword.operator.assignment.java
@ -139,4 +140,3 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ PunctuationBracket punctuation.section.block.end.java
}
//^ PunctuationBracket punctuation.section.block.end.java

View File

@ -3,6 +3,7 @@ source: crates/syntax-analysis/src/highlighting/syntect_scip.rs
expression: "snapshot_sciptect_documents(&document, &contents)"
---
#!/bin/sh
//^ Comment punctuation.definition.comment.begin.shell
// ^^^^^^^^ Comment comment.line.number-sign.shell
export RUNTIME_IMAGE="sourcegraph/ignite:${IGNITE_VERSION}"
@ -14,4 +15,3 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ PunctuationBracket punctuation.section.expansion.parameter.begin.shell
// ^^^^^^^^^^^^^^ Identifier variable.other.readwrite.shell
// ^ PunctuationBracket punctuation.section.expansion.parameter.end.shell

View File

@ -3,6 +3,7 @@ source: crates/syntax-analysis/src/highlighting/syntect_scip.rs
expression: "snapshot_sciptect_documents(&document, &contents)"
---
#!/bin/sh
//^ Comment punctuation.definition.comment.begin.shell
// ^^^^^^^^ Comment comment.line.number-sign.shell
set -eux
//^^^ IdentifierFunction support.function.set.shell
@ -31,13 +32,13 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^^^ IdentifierOperator keyword.operator.end-of-options.shell
// ^ IdentifierOperator keyword.operator.logical.pipe.shell
# some comment
// ^ Comment comment.line.number-sign.shell
// ^ Comment punctuation.definition.comment.begin.shell
// ^^^^^^^^^^^^^ Comment comment.line.number-sign.shell
grep ^+ |
// ^^^^ IdentifierFunction variable.function.shell
// ^ IdentifierOperator keyword.operator.logical.pipe.shell
# more sed
// ^ Comment comment.line.number-sign.shell
// ^ Comment punctuation.definition.comment.begin.shell
// ^^^^^^^^^ Comment comment.line.number-sign.shell
sed 's/#readme//')
// ^^^ IdentifierFunction variable.function.shell
@ -77,4 +78,3 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^^^^^ StringLiteral string.quoted.single.shell
fi
//^^ Keyword keyword.control.conditional.end.shell

View File

@ -0,0 +1,15 @@
---
source: crates/syntax-analysis/src/highlighting/syntect_scip.rs
expression: "snapshot_sciptect_documents(&document, &contents)"
---
// Package log is cool!
//^^ Comment punctuation.definition.comment.go
// ^^^^^^^^^^^^^^^^^^^^^ Comment comment.line.go
//
//^^ Comment punctuation.definition.comment.go
// Learn more: https://docs.sourcegraph.com/dev/how-to/add_logging
//^^ Comment punctuation.definition.comment.go
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Comment comment.line.go
package log
//^^^^^^^ Keyword keyword.other.package.go
// ^^^ Identifier variable.other.go

View File

@ -0,0 +1,17 @@
---
source: crates/syntax-analysis/src/highlighting/syntect_scip.rs
expression: "snapshot_sciptect_documents(&document, &contents)"
---
"""This is my amazing module"""
//^^^ Comment punctuation.definition.comment.begin.python
// ^^^^^^^^^^^^^^^^^^^^^^^^^ Comment punctuation.definition.comment.end.python
// ^^^ Comment punctuation.definition.comment.end.python
def foo():
//^^^ Keyword keyword.declaration.function.python
// ^^^ IdentifierFunction entity.name.function.python
// ^ PunctuationBracket punctuation.section.parameters.begin.python
// ^ PunctuationBracket punctuation.section.parameters.end.python
// ^ PunctuationBracket punctuation.section.function.begin.python
pass
// ^^^^ Keyword keyword.control.flow.pass.python

View File

@ -52,7 +52,8 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ PunctuationBracket punctuation.section.parens.end.go
// ^ PunctuationBracket punctuation.section.braces.begin.go
// this is comment
// ^^^^^^^^^^^^^^^^^^ Comment comment.line.go
// ^^ Comment punctuation.definition.comment.go
// ^^^^^^^^^^^^^^^^ Comment comment.line.go
x := 1234
// ^ Identifier variable.declaration.go
@ -140,4 +141,3 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ PunctuationBracket punctuation.section.parens.end.go
}
//^ PunctuationBracket punctuation.section.braces.end.go

View File

@ -66,15 +66,21 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^^^^ Identifier entity.name.tag.structure.any.html
// ^ PunctuationBracket punctuation.definition.tag.end.html
<!-- This is a comment -->
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ Comment comment.block.html
// ^^^^ Comment punctuation.definition.comment.begin.html
// ^^^^^^^^^^^^^^^^^^^ Comment punctuation.definition.comment.end.html
// ^^^ Comment punctuation.definition.comment.end.html
<style>
// ^ PunctuationBracket punctuation.definition.tag.begin.html
// ^^^^^ Identifier entity.name.tag.style.html
// ^ PunctuationBracket punctuation.definition.tag.end.html
/*
//^^ Comment 11:0..13:3 comment.block.css
//^^ Comment punctuation.definition.comment.css
// Comment 11:2..12:1 punctuation.definition.comment.css
* Positions
// ^ Comment punctuation.definition.comment.css
// ^^^^^^^^^^ Comment 12:2..13:1 punctuation.definition.comment.css
*/
// ^^ Comment punctuation.definition.comment.css
.center,
//^ PunctuationBracket punctuation.definition.entity.css
// ^^^^^^ Identifier entity.other.attribute-name.class.css
@ -202,4 +208,3 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
//^^ PunctuationBracket punctuation.definition.tag.begin.html
// ^^^^ Identifier entity.name.tag.structure.any.html
// ^ PunctuationBracket punctuation.definition.tag.end.html

View File

@ -86,7 +86,9 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ PunctuationBracket punctuation.section.group.end.js
// ^ PunctuationBracket punctuation.section.block.begin.js
/* handle exception */
// ^^^^^^^^^^^^^^^^^^^^^^ Comment comment.block.js
// ^^ Comment punctuation.definition.comment.begin.js
// ^^^^^^^^^^^^^^^^^^ Comment punctuation.definition.comment.end.js
// ^^ Comment punctuation.definition.comment.end.js
}
// ^ PunctuationBracket punctuation.section.block.end.js
for (var i = 0 / 2; i < classes.length; i++) {
@ -164,4 +166,3 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
//^^^^^^ Keyword keyword.control.import-export.js
// ^^^^^^^^^^^^^^ Identifier variable.other.readwrite.js
// ^ PunctuationDelimiter punctuation.terminator.statement.js

View File

@ -86,7 +86,9 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ PunctuationBracket punctuation.section.group.end.js
// ^ PunctuationBracket punctuation.section.block.begin.js
/* handle exception */
// ^^^^^^^^^^^^^^^^^^^^^^ Comment comment.block.js
// ^^ Comment punctuation.definition.comment.begin.js
// ^^^^^^^^^^^^^^^^^^ Comment punctuation.definition.comment.end.js
// ^^ Comment punctuation.definition.comment.end.js
}
// ^ PunctuationBracket punctuation.section.block.end.js
for (var i = 0 / 2; i < classes.length; i++) {
@ -164,4 +166,3 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
//^^^^^^ Keyword keyword.control.import-export.js
// ^^^^^^^^^^^^^^ Identifier variable.other.readwrite.js
// ^ PunctuationDelimiter punctuation.terminator.statement.js

View File

@ -24,13 +24,15 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ IdentifierOperator keyword.operator.dot.kotlin
/***
//^^^^ Comment 6:0..12:3 comment.block.kotlin
//^^ Comment punctuation.definition.comment.kotlin
// ^^ Comment 6:2..12:1 punctuation.definition.comment.kotlin
* Example use:
*
* val (b, g, r) = mat.at<UByte>(50, 50).v3c
* mat.at<UByte>(50, 50).val = T3(245u, 113u, 34u)
*
*/
// ^^ Comment punctuation.definition.comment.kotlin
@Suppress("UNCHECKED_CAST")
// ^^^^^^^^^^^^^^^^ StringLiteral string.quoted.double.kotlin
inline fun <reified T> Mat.at(row: Int, col: Int) : Atable<T> =
@ -64,10 +66,12 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
/**
//^^^ Comment 21:0..24:3 comment.block.kotlin
//^^ Comment punctuation.definition.comment.kotlin
// ^ Comment 21:2..24:1 punctuation.definition.comment.kotlin
* Implementation of [DataAccess] which handles access and interactions with file and data
* under scoped storage via the MediaStore API.
*/
// ^^ Comment punctuation.definition.comment.kotlin
@RequiresApi(Build.VERSION_CODES.Q)
// ^ IdentifierOperator keyword.operator.dot.kotlin
// ^ IdentifierOperator keyword.operator.dot.kotlin
@ -172,4 +176,3 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ IdentifierOperator keyword.operator.dot.kotlin
}
}

View File

@ -3,9 +3,11 @@ source: crates/syntax-analysis/src/highlighting/syntect_scip.rs
expression: "snapshot_sciptect_documents(&document, &contents)"
---
// Original:
//^^ Comment punctuation.definition.comment.cs
// ^^^^^^^^^^ Comment comment.line.double-slash.cs
// repo:^github\.com/radzenhq/radzen-blazor$ file:^Radzen\.Blazor\.Tests/DataGridTests\.cs
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Comment comment.line.double-slash.cs
//^^ Comment punctuation.definition.comment.cs
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Comment comment.line.double-slash.cs
using AngleSharp.Dom;
//^^^^^ Keyword keyword.control.import.cs
@ -80,7 +82,8 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
{
// ^ PunctuationBracket punctuation.section.block.begin.cs
// Css classes tests
// ^^^^^^^^^^^^^^^^^^^^ Comment comment.line.double-slash.cs
// ^^ Comment punctuation.definition.comment.cs
// ^^^^^^^^^^^^^^^^^^ Comment comment.line.double-slash.cs
[Fact]
// ^ PunctuationBracket punctuation.definition.annotation.begin.cs
// ^^^^ Identifier variable.annotation.cs
@ -249,7 +252,8 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ PunctuationDelimiter punctuation.terminator.statement.cs
// Main
// ^^^^^^^ Comment comment.line.double-slash.cs
// ^^ Comment punctuation.definition.comment.cs
// ^^^^^ Comment comment.line.double-slash.cs
Assert.Contains(@$"rz-datatable-scrollable-wrapper", component.Markup);
// ^^^^^^ Identifier variable.other.cs
// ^ PunctuationBracket punctuation.accessor.dot.cs
@ -484,4 +488,3 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ PunctuationBracket punctuation.section.block.end.cs
}
//^ PunctuationBracket punctuation.section.block.end.cs

View File

@ -14,7 +14,8 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ PunctuationBracket punctuation.section.group.end.c
// ^ PunctuationBracket punctuation.section.block.begin.c
// Single line comment
// ^^^^^^^^^^^^^^^^^^^^^^ Comment comment.line.double-slash.c
// ^^ Comment punctuation.definition.comment.c
// ^^^^^^^^^^^^^^^^^^^^ Comment comment.line.double-slash.c
int x = 1;
// ^^^ IdentifierType storage.type.c
// ^ IdentifierOperator keyword.operator.assignment.c
@ -22,13 +23,16 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ PunctuationDelimiter punctuation.terminator.c
/*
// ^^ Comment 6:2..8:5 comment.block.c
// ^^ Comment punctuation.definition.comment.c
// Comment 6:4..7:3 punctuation.definition.comment.c
*Multi Line
// ^ Comment punctuation.definition.comment.c
// ^^^^^^^^^^ Comment 7:4..8:3 punctuation.definition.comment.c
*/
// ^^ Comment punctuation.definition.comment.c
return x;
// ^^^^^^ Keyword keyword.control.flow.return.c
// ^ PunctuationDelimiter punctuation.terminator.c
}
//^ PunctuationBracket punctuation.section.block.end.c

View File

@ -29,12 +29,15 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ PunctuationBracket punctuation.section.function.begin.python
r'''A docstring'''
// ^ IdentifierType storage.type.string.python
// ^^^^^^^^^^^^^^^^^ Comment comment.block.documentation.python
// ^^^ Comment punctuation.definition.comment.begin.python
// ^^^^^^^^^^^ Comment punctuation.definition.comment.end.python
// ^^^ Comment punctuation.definition.comment.end.python
if param1 > param2: # interesting
// ^^ Keyword keyword.control.conditional.if.python
// ^ IdentifierOperator keyword.operator.comparison.python
// ^ PunctuationBracket punctuation.section.block.conditional.if.python
// ^^^^^^^^^^^^^ Comment comment.line.number-sign.python
// ^ Comment punctuation.definition.comment.python
// ^^^^^^^^^^^^ Comment comment.line.number-sign.python
print 'Gre\'ater'
// ^^^^^ Keyword keyword.other.print.python
// ^ StringLiteral string.quoted.single.python
@ -61,4 +64,3 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ PunctuationBracket punctuation.section.class.begin.python
pass
// ^^^^ Keyword keyword.control.flow.pass.python

View File

@ -24,7 +24,8 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
name IN (
// ^^ Keyword keyword.operator.logical.sql
-- The events that share a line are events that changed names and are aliases of each other
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Comment comment.line.double-dash.sql
// ^^ Comment punctuation.definition.comment.sql
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Comment comment.line.double-dash.sql
'CodeMonitoringLogsPageViewed'
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ StringLiteral string.quoted.single.sql
)
@ -43,4 +44,3 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
action_jobs,
trigger_jobs
;

View File

@ -37,9 +37,13 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
/*
//^^ Comment 9:0..11:3 comment.block.css
//^^ Comment punctuation.definition.comment.css
// Comment 9:2..10:1 punctuation.definition.comment.css
* Positions
// ^ Comment punctuation.definition.comment.css
// ^^^^^^^^^^ Comment 10:2..11:1 punctuation.definition.comment.css
*/
// ^^ Comment punctuation.definition.comment.css
.center,
//^ PunctuationBracket punctuation.definition.entity.css
// ^^^^^^ Identifier entity.other.attribute-name.class.css
@ -83,4 +87,3 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ PunctuationDelimiter punctuation.terminator.rule.css
}
//^ PunctuationBracket punctuation.section.property-list.css

View File

@ -506,7 +506,7 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ PunctuationBracket punctuation.definition.block.tsx
// ^ PunctuationBracket meta.brace.round.tsx
// ^ PunctuationDelimiter punctuation.terminator.statement.tsx
// ^^ Comment comment.line.double-slash.tsx
// ^^ Comment punctuation.definition.comment.tsx
// ^^^^^^^^^^^^^^^^^ Comment comment.line.double-slash.tsx
const oneOf = (a:number): number => a + 1
//^^^^^ Keyword storage.type.tsx
@ -748,5 +748,3 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ IdentifierOperator keyword.operator.type.annotation.tsx
// ^^^^^^ Keyword keyword.operator.expression.typeof.tsx
// ^^^ IdentifierType entity.name.type.tsx

View File

@ -93,7 +93,7 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
// ^ PunctuationBracket punctuation.definition.block.ts
// ^ PunctuationBracket meta.brace.round.ts
// ^ PunctuationDelimiter punctuation.terminator.statement.ts
// ^^ Comment comment.line.double-slash.ts
// ^^ Comment punctuation.definition.comment.ts
// ^^^^^^^^^^^^^^^^^ Comment comment.line.double-slash.ts
const oneOf = (a:number): number => a + 1
//^^^^^ Keyword storage.type.ts
@ -396,4 +396,3 @@ expression: "snapshot_sciptect_documents(&document, &contents)"
}
//^ PunctuationBracket punctuation.definition.block.ts

View File

@ -0,0 +1,4 @@
// Package log is cool!
//
// Learn more: https://docs.sourcegraph.com/dev/how-to/add_logging
package log

View File

@ -0,0 +1,4 @@
"""This is my amazing module"""
def foo():
pass

View File

@ -45,7 +45,6 @@ fn should_skip_scope(scope: &Scope) -> bool {
scope("punctuation.definition.metadata.end"),
scope("punctuation.definition.string.begin"),
scope("punctuation.definition.string.end"),
scope("punctuation.definition.comment"),
]
})
.iter()
@ -75,6 +74,7 @@ fn match_scope_to_kind(scope: &Scope) -> Option<SyntaxKind> {
vec![
(scope("comment"), Comment),
(scope("meta.documentation"), Comment),
(scope("punctuation.definition.comment"), Comment),
// TODO: How does this play with this: keyword.control.import.include
(scope("meta.preprocessor.include"), IdentifierNamespace),
(scope("storage.type.keyword"), IdentifierKeyword),