Skip to content

Support markdown code blocks as "cell" #2410

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
Jun 14, 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
57 changes: 57 additions & 0 deletions data/fixtures/scopes/markdown/notebookCell.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
```python
def foo():
pass
```

```
hello
```

---

[#1 Content] =
[#1 Removal] =
[#1 Domain] = 0:0-3:3
>---------
0| ```python
1| def foo():
2| pass
3| ```
---<

[#1 Interior: Content] = 1:0-2:8
>----------
1| def foo():
2| pass
--------<
[#1 Interior: Removal] = 0:9-3:0
>
0| ```python
1| def foo():
2| pass
3| ```
<

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


[#2 Content] =
[#2 Removal] =
[#2 Domain] = 5:0-7:3
>---
5| ```
6| hello
7| ```
---<

[#2 Interior: Content] = 6:0-6:5
>-----<
6| hello
[#2 Interior: Removal] = 5:3-7:0
>
5| ```
6| hello
7| ```
<

[#2 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 @@ -11,4 +11,5 @@ const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel;
export const markdownScopeSupport: LanguageScopeSupportFacetMap = {
"comment.line": supported,
"comment.block": supported,
notebookCell: supported,
};
Original file line number Diff line number Diff line change
Expand Up @@ -622,4 +622,9 @@ export const scopeSupportFacetInfos: Record<
scopeType: "type",
isIteration: true,
},

notebookCell: {
description: "A cell in a notebook or a markdown code block",
scopeType: "notebookCell",
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ const scopeSupportFacets = [
"type.typeArgument",
"type.typeArgument.iteration",

"notebookCell",

// FIXME: Still in legacy
// section
// selector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import {
CommandLatest,
EnforceUndefined,
LATEST_VERSION,
Modifier,
OutdatedExtensionError,
PartialTargetDescriptor,
SimpleScopeTypeType,
} from "@cursorless/common";
import { getPartialTargetDescriptors } from "../../util/getPartialTargetDescriptors";
import { getPartialPrimitiveTargets } from "../../util/getPrimitiveTargets";
import canonicalizeTargetsInPlace from "./canonicalizeTargetsInPlace";
import { upgradeV0ToV1 } from "./upgradeV0ToV1";
import { upgradeV1ToV2 } from "./upgradeV1ToV2";
Expand Down Expand Up @@ -90,29 +87,14 @@ function upgradeCommand(command: Command): CommandLatest {
return command;
}

/**
* Validates the given action. Today, this function is a no-op, but in the
* future it may perform additional validation.
*
* @param _actionName The name of the action
* @param _partialTargets The partial targets of the action
*/
function validateCommand(
actionName: ActionType,
partialTargets: PartialTargetDescriptor[],
): void {
if (
usesScopeType("notebookCell", partialTargets) &&
!["editNewLineBefore", "editNewLineAfter"].includes(actionName)
) {
throw new Error(
"The notebookCell scope type is currently only supported with the actions editNewLineAbove and editNewLineBelow",
);
}
}

function usesScopeType(
scopeTypeType: SimpleScopeTypeType,
partialTargets: PartialTargetDescriptor[],
) {
return getPartialPrimitiveTargets(partialTargets).some((partialTarget) =>
partialTarget.modifiers?.find(
(mod: Modifier) =>
(mod.type === "containingScope" || mod.type === "everyScope") &&
mod.scopeType.type === scopeTypeType,
),
);
}
_actionName: ActionType,
_partialTargets: PartialTargetDescriptor[],
): void {}
34 changes: 34 additions & 0 deletions queries/markdown.scm
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,37 @@
)

(list) @collectionItem.iteration

;;!! ```
;;! ^^^
;;!! hello
;;! -----
;;! #####
;;!! ```
;;! ^^^
(
(fenced_code_block
(fenced_code_block_delimiter) @_.interior.start.endOf
.
(block_continuation)
(fenced_code_block_delimiter) @_.interior.end.startOf
) @notebookCell
(#trim-end! @notebookCell)
(#insertion-delimiter! @notebookCell "\n\n")
)

;;!! ```python
;;! ^^^^^^^^^
;;!! pass
;;! ----
;;! ####
;;!! ```
;;! ^^^
(
(fenced_code_block
(info_string) @_.interior.start.endOf
(fenced_code_block_delimiter) @_.interior.end.startOf
) @notebookCell
(#trim-end! @notebookCell)
(#insertion-delimiter! @notebookCell "\n\n")
)
Loading