Skip to content

Migrating markdown scopes #2489

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

Merged
merged 3 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions data/fixtures/scopes/markdown/section.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# H1

Sub 1

## H2

Sub 2

# H1.2
---

[#1 Content] =
[#1 Domain] = 0:0-6:5
>----
0| # H1
1|
2| Sub 1
3|
4| ## H2
5|
6| Sub 2
-----<

[#1 Removal] = 0:0-8:0
>----
0| # H1
1|
2| Sub 1
3|
4| ## H2
5|
6| Sub 2
7|
8| # H1.2
<

[#1 Insertion delimiter] = "\n\n"


[#2 Content] =
[#2 Domain] = 4:0-6:5
>-----
4| ## H2
5|
6| Sub 2
-----<

[#2 Removal] = 4:0-8:0
>-----
4| ## H2
5|
6| Sub 2
7|
8| # H1.2
<

[#2 Insertion delimiter] = "\n\n"


[#3 Content] =
[#3 Removal] =
[#3 Domain] = 8:0-8:6
>------<
8| # H1.2

[#3 Insertion delimiter] = "\n\n"
1 change: 1 addition & 0 deletions packages/common/src/scopeSupportFacets/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel;
export const markdownScopeSupport: LanguageScopeSupportFacetMap = {
"comment.line": supported,
"comment.block": supported,
section: supported,
notebookCell: supported,
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export const scopeSupportFacetInfos: Record<
scopeType: "environment",
},

section: {
description: "A document section",
scopeType: "section",
},

list: {
description: "A list/array",
scopeType: "list",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const scopeSupportFacets = [

"environment",

"section",

"list",
"map",
"ifStatement",
Expand Down Expand Up @@ -162,7 +164,6 @@ const scopeSupportFacets = [
"notebookCell",

// FIXME: Still in legacy
// section
// selector
// unit
// collectionItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const legacyLanguageIds = [
"csharp",
"css",
"latex",
"markdown",
"php",
"ruby",
"rust",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,12 @@ class TrimEnd extends QueryPredicateOperator<TrimEnd> {
const { document, range } = nodeInfo;
const text = document.getText(range);
const whitespaceLength = text.length - text.trimEnd().length;
nodeInfo.range = new Range(
range.start,
adjustPosition(document, range.end, -whitespaceLength),
);
if (whitespaceLength > 0) {
nodeInfo.range = new Range(
range.start,
adjustPosition(document, range.end, -whitespaceLength),
);
}
return true;
}
}
Expand Down
33 changes: 0 additions & 33 deletions packages/cursorless-engine/src/languages/branchMatcher.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/cursorless-engine/src/languages/getNodeMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import clojure from "./clojure";
import { LegacyLanguageId } from "./LegacyLanguageId";
import csharp from "./csharp";
import latex from "./latex";
import markdown from "./markdown";
import php from "./php";
import { patternMatchers as ruby } from "./ruby";
import rust from "./rust";
Expand Down Expand Up @@ -51,7 +50,6 @@ export const languageMatchers: Record<
csharp,
css: scss,
latex,
markdown,
php,
ruby,
rust,
Expand Down
76 changes: 0 additions & 76 deletions packages/cursorless-engine/src/languages/markdown.ts

This file was deleted.

This file was deleted.

58 changes: 58 additions & 0 deletions queries/markdown.scm
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,61 @@
(#trim-end! @notebookCell)
(#insertion-delimiter! @notebookCell "\n\n")
)

;;!! # H1
;;!! ## H2
(
(section) @section @_.removal
(#trim-end! @section)
)

;;!! # H1
(
(section
(atx_heading
(atx_h1_marker)
)
) @sectionLevelOne @_.removal
(#trim-end! @sectionLevelOne)
)
;;!! ## H2
(
(section
(atx_heading
(atx_h2_marker)
)
) @sectionLevelTwo @_.removal
(#trim-end! @sectionLevelTwo)
)
(
(section
(atx_heading
(atx_h3_marker)
)
) @sectionLevelThree @_.removal
(#trim-end! @sectionLevelThree)
)
(
(section
(atx_heading
(atx_h4_marker)
)
) @sectionLevelFour @_.removal
(#trim-end! @sectionLevelFour)
)
(
(section
(atx_heading
(atx_h5_marker)
)
) @sectionLevelFive @_.removal
(#trim-end! @sectionLevelFive)
)
(
(section
(atx_heading
(atx_h6_marker)
)
) @sectionLevelSix @_.removal
(#trim-end! @sectionLevelSix)
)
Loading