-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
346dd7f
commit b6b641d
Showing
12 changed files
with
133 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@mdx-js/language-service": patch | ||
"@mdx-js/language-server": patch | ||
"vscode-mdx": patch | ||
--- | ||
|
||
Report syntax errors. |
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 @@ | ||
export 1/1 |
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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export {createMdxLanguagePlugin} from './lib/language-plugin.js' | ||
export {createMdxServicePlugin} from './lib/service-plugin.js' |
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,67 @@ | ||
/** | ||
* @typedef {import('@volar/language-service').ServicePlugin} ServicePlugin | ||
*/ | ||
|
||
import {fromPlace} from 'unist-util-lsp' | ||
import {VirtualMdxFile} from './virtual-file.js' | ||
|
||
/** | ||
* Create an Volar service plugin for MDX files. | ||
* | ||
* The service supports reporting diagnostics for parsing errors. | ||
* | ||
* @returns {ServicePlugin} | ||
* The Volar service plugin for MDX files. | ||
*/ | ||
export function createMdxServicePlugin() { | ||
return { | ||
create(context) { | ||
return { | ||
provideSemanticDiagnostics(document) { | ||
const file = getVirtualMdxFile(document.uri) | ||
|
||
const error = file?.error | ||
|
||
if (error) { | ||
return [ | ||
{ | ||
message: error.message, | ||
code: error.ruleId, | ||
codeDescription: { | ||
href: | ||
error.url || 'https://mdxjs.com/docs/troubleshooting-mdx/' | ||
}, | ||
range: error.place | ||
? fromPlace(error.place) | ||
: { | ||
start: {line: 0, character: 0}, | ||
end: {line: 0, character: 0} | ||
}, | ||
severity: 1, | ||
source: 'MDX' | ||
} | ||
] | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Get the virtual MDX file that matches a document uri. | ||
* | ||
* @param {string} uri | ||
* The uri of which to find the matching virtual MDX file. | ||
* @returns {VirtualMdxFile | undefined} | ||
* The matching virtual MDX file, if it exists. Otherwise undefined. | ||
*/ | ||
function getVirtualMdxFile(uri) { | ||
const [file] = context.language.files.getVirtualFile( | ||
context.env.uriToFileName(uri) | ||
) | ||
|
||
if (file instanceof VirtualMdxFile) { | ||
return file | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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