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

Allow extension to activate in MDX files #759

Merged
merged 3 commits into from
Jul 23, 2020

Conversation

thomaskoppelaar
Copy link
Contributor

Allows for the extension to work within MDX files.

Caveat: The "Print current page to HTML" command won't properly convert MDX into HTML; It will treat the document as markdown.

@thomaskoppelaar
Copy link
Contributor Author

I don't speak Japanese nor Chinese, so those translations will need to be edited (they're currently English).

@thomaskoppelaar
Copy link
Contributor Author

I'm also unsure as to why the first test fails on the CI, I've run the tests locally to check if they still work + I've not modified anything specific to that function.

@yzhang-gh
Copy link
Owner

I don't speak Japanese nor Chinese, so those translations will need to be edited (they're currently English).

No worries. We can rely on other users who would like to help 🤣.

I'm also unsure as to why the first test fails on the CI, I've run the tests locally to check if they still work + I've not modified anything specific to that function.

Sometimes it fails because of "time-out".

Many thanks!

@yzhang-gh yzhang-gh merged commit 10e0777 into yzhang-gh:master Jul 23, 2020
Copy link
Collaborator

@Lemmingh Lemmingh left a comment

Choose a reason for hiding this comment

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

I'm afraid injectTo is only valid under the grammars contribution point, which is designed to extend an existing grammar in a specific scope. And it only works when injectionSelector is declared properly in the TM grammar.

See also https://github.com/microsoft/vscode/blob/85d983391a3c1ff65db6746b8c6994ec0833b3d8/src/vs/workbench/services/textMate/common/TMGrammars.ts


Link #758

Comment on lines +94 to +231
"key": "shift+enter",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onTabKey",
"key": "tab",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible && !editorTabMovesFocus && !inSnippetMode && !hasSnippetCompletions && !hasOtherSuggestions"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible && !editorTabMovesFocus && !inSnippetMode && !hasSnippetCompletions && !hasOtherSuggestions",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onShiftTabKey",
"key": "shift+tab",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible && !editorTabMovesFocus && !inSnippetMode && !hasSnippetCompletions && !hasOtherSuggestions"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible && !editorTabMovesFocus && !inSnippetMode && !hasSnippetCompletions && !hasOtherSuggestions",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onBackspaceKey",
"key": "backspace",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible && vim.mode != 'Normal' && vim.mode != 'Visual' && vim.mode != 'VisualBlock' && vim.mode != 'VisualLine' && vim.mode != 'SearchInProgressMode' && vim.mode != 'CommandlineInProgress' && vim.mode != 'Replace' && vim.mode != 'EasyMotionMode' && vim.mode != 'EasyMotionInputMode' && vim.mode != 'SurroundInputMode'"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible && vim.mode != 'Normal' && vim.mode != 'Visual' && vim.mode != 'VisualBlock' && vim.mode != 'VisualLine' && vim.mode != 'SearchInProgressMode' && vim.mode != 'CommandlineInProgress' && vim.mode != 'Replace' && vim.mode != 'EasyMotionMode' && vim.mode != 'EasyMotionInputMode' && vim.mode != 'SurroundInputMode'",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onMoveLineUp",
"key": "alt+up",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onMoveLineDown",
"key": "alt+down",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onCopyLineUp",
"key": "shift+alt+up",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onCopyLineDown",
"key": "shift+alt+down",
"when": "editorTextFocus && !editorReadonly && editorLangId == markdown && !suggestWidgetVisible"
"when": "editorTextFocus && !editorReadonly && !suggestWidgetVisible",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onIndentLines",
"key": "ctrl+]",
"mac": "cmd+]",
"when": "editorTextFocus && editorLangId == markdown && !suggestWidgetVisible"
"when": "editorTextFocus && !suggestWidgetVisible",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.onOutdentLines",
"key": "ctrl+[",
"mac": "cmd+[",
"when": "editorTextFocus && editorLangId == markdown && !suggestWidgetVisible"
"when": "editorTextFocus && !suggestWidgetVisible",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.checkTaskList",
"key": "alt+c",
"when": "editorTextFocus && editorLangId == markdown"
"when": "editorTextFocus",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.togglePreview",
"key": "ctrl+shift+v",
"mac": "cmd+shift+v",
"when": "!terminalFocus"
"when": "!terminalFocus",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.togglePreviewToSide",
"key": "ctrl+k v",
"mac": "cmd+k v",
"when": "!terminalFocus"
"when": "!terminalFocus",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
},
{
"command": "markdown.extension.editing.paste",
"key": "ctrl+v",
"mac": "cmd+v",
"when": "editorTextFocus && editorLangId == markdown && editorHasSelection"
"when": "editorTextFocus && editorHasSelection",
"injectTo": ["text.html.markdown.jsx", "text.html.markdown"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment on lines +425 to +434
"text.html.markdown",
"text.html.markdown.jsx"
]
},
{
"scopeName": "markdown.math_inline",
"path": "./syntaxes/math_inline.markdown.tmLanguage.json",
"injectTo": [
"text.html.markdown"
"text.html.markdown",
"text.html.markdown.jsx"
Copy link
Collaborator

Choose a reason for hiding this comment

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

There seems to be nothing about LaTeX in JSX. Is it correct to inject them to text.html.markdown.jsx scope?

Comment on lines +440 to +443
"injectTo": [
"text.html.markdown",
"text.html.markdown.jsx"
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I cannot understand this change.


{
    "scopeName": "text.katex",
    "path": "./syntaxes/katex.tmLanguage.json"
}

was intended to simply import the TM grammar, because math_display.markdown.tmLanguage.json and math_inline.markdown.tmLanguage.json reference text.katex scope.

I think there should be no need to inject it into any scope.

@@ -10,10 +10,10 @@ import { mdEngine } from './markdownEngine';
└────────┘ */

/** Scheme `File` or `Untitled` */
export const mdDocSelector = [{ language: 'markdown', scheme: 'file' }, { language: 'markdown', scheme: 'untitled' }];
export const mdDocSelector = [{ language: 'markdown', scheme: 'file' }, { language: 'markdown', scheme: 'untitled' }, { language: 'mdx', scheme: 'file' }, { language: 'mdx', scheme: 'file' }];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why twice?

@yzhang-gh
Copy link
Owner

I'm afraid injectTo is only valid under the grammars contribution point, which is designed to extend an existing grammar in a specific scope. And it only works when injectionSelector is declared properly in the TM grammar.

@Lemmingh Thanks for the important information! I thought embedded language support had been implemented 😅 (see microsoft/vscode#1751) so I didn't check.

@thomaskoppelaar I have to revert this PR as this extension now activates in all documents (e.g. json). Probably we can have a better solution later.

@Lemmingh
Copy link
Collaborator

embedded language support

Yeah. The universal solution doesn't exist yet. And I'm not optimistic about it, given the complexity of designing a universal way to declare matching pattern and algorithm, and related mechanisms.

However, "hardcoded" embedded language support have been available for a long time. The VS Code team encourages extensions to adopt it with examples for both declarative and programmatic language features.

Opinions from Matt Bierner:
https://twitter.com/mattbierner/status/1017118184699133952
microsoft/vscode#71888 (comment)

@thomaskoppelaar
Copy link
Contributor Author

@Lemmingh thank you for the feedback and clarification! Like you said, I misunderstood the way injectTo works.

@Lemmingh Lemmingh linked an issue Dec 22, 2020 that may be closed by this pull request
@Lemmingh Lemmingh added the Res: Invalid This does not seem right, or contain any valid or useful information. It's discarded. label Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Res: Invalid This does not seem right, or contain any valid or useful information. It's discarded.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggestion: Allow extension to work within MDX files
3 participants