-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(folding): support regions comments & eof & more (#1)
* more tests and more stuff * fix(folding): correctly detect single-line region comments * fix(folding): correctly handle nested region comments * fix: wrong block kind * feat(folding): Add benchmarks * fix: run all benchs * Actually, Erika wants us to use the text again * fix: lint * fix bed tests && tests in another file * fix TS test * perf(folding): reuse cached line indices * fix lint * doc: jsdoc on wasm function * typo --------- Co-authored-by: Erika <[email protected]>
- Loading branch information
1 parent
ae1165b
commit 9d64614
Showing
10 changed files
with
764 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use criterion::criterion_main; | ||
|
||
mod features; | ||
|
||
criterion_main!(features::folding::benches, features::color::benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use criterion::{criterion_group, Criterion}; | ||
use csslsrs::service::LanguageService; | ||
use lsp_types::{TextDocumentItem, Uri}; | ||
use std::{hint::black_box, str::FromStr}; | ||
|
||
static TEST_CASE: &str = r#" | ||
body { | ||
background-color: #fff; | ||
} | ||
a { | ||
color: red; | ||
} | ||
h1 { | ||
color: rgba(0, 0, 0, 0.5); | ||
} | ||
h2 { | ||
color: linear-gradient(to right, red, #fff); | ||
} | ||
//#region Outer Region | ||
h3 { | ||
color: hsl(120, 100%, 50%); | ||
} | ||
//#region Inner Region | ||
h4 { | ||
color: hwb(120, 0%, 0%); | ||
} | ||
//#endregion | ||
//#endregion | ||
@media (max-width: 600px) { | ||
body { | ||
background-color: #000; | ||
} | ||
} | ||
"#; | ||
|
||
fn get_folding_ranges_benchmark(c: &mut Criterion) { | ||
let mut ls = LanguageService::default(); | ||
|
||
let document = TextDocumentItem { | ||
uri: Uri::from_str("file:///test.css").unwrap(), | ||
language_id: "css".to_string(), | ||
version: 0, | ||
text: TEST_CASE.to_string(), | ||
}; | ||
|
||
c.bench_function("get_folding_ranges", |b| { | ||
b.iter(|| ls.get_folding_ranges(black_box(document.clone()))) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, get_folding_ranges_benchmark); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod color; | ||
pub mod folding; |
55 changes: 55 additions & 0 deletions
55
csslsrs/packages/benchmark-wasm/benchmarks/folding_ranges.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Bench } from "tinybench"; | ||
import { get_folding_ranges } from "csslsrs"; | ||
import { getCSSLanguageService } from "vscode-css-languageservice"; | ||
import { TextDocument } from "vscode-languageserver-textdocument"; | ||
|
||
const bench = new Bench({ name: "Folding Ranges", time: 100 }); | ||
|
||
const vscodeLanguageService = getCSSLanguageService(); | ||
const content = ` | ||
body { | ||
background-color: #fff; | ||
} | ||
a { | ||
color: red; | ||
} | ||
h1 { | ||
color: rgba(0, 0, 0, 0.5); | ||
} | ||
h2 { | ||
color: linear-gradient(to right, red, #fff); | ||
} | ||
//#region Outer Region | ||
h3 { | ||
color: hsl(120, 100%, 50%); | ||
} | ||
//#region Inner Region | ||
h4 { | ||
color: hwb(120, 0%, 0%); | ||
} | ||
//#endregion | ||
//#endregion | ||
@media (max-width: 600px) { | ||
body { | ||
background-color: #000; | ||
} | ||
} | ||
`; | ||
|
||
const textDocument = TextDocument.create("file:///test.css", "css", 0, content); | ||
|
||
bench | ||
.add("CSSLSRS - WASM", async () => { | ||
await get_folding_ranges(textDocument); | ||
}) | ||
.add("vscode-css-languageservice", () => { | ||
const stylesheet = vscodeLanguageService.parseStylesheet(textDocument); | ||
vscodeLanguageService.getFoldingRanges(textDocument, stylesheet); | ||
}); | ||
|
||
export default bench; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.