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

Adjust twoslash inlay provider to use the new Monaco API for that #2273

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@rollup/plugin-typescript": "^3.0.0",
"@types/react": "^16.9.23",
"concurrently": "^5.1.0",
"monaco-editor": "^0.29.1",
"monaco-editor": "^0.32.1",
"node-fetch": "^2.6.0",
"rollup": "^1.31.0",
"serve": "^11.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"devDependencies": {
"@types/jest": "^25.1.3",
"jest": "*",
"monaco-editor": "^0.29.1",
"monaco-editor": "^0.32.1",
"monaco-typescript": "^3.7.0",
"typescript": "*"
}
Expand Down
6 changes: 5 additions & 1 deletion packages/playground/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,11 @@ export const setupPlayground = (
}
}

if (monaco.languages.registerInlayHintsProvider) {
const [tsMajor, tsMinor] = sandbox.ts.version.split(".")
if (
(parseInt(tsMajor) > 4 || (parseInt(tsMajor) == 4 && parseInt(tsMinor) >= 6)) &&
monaco.languages.registerInlayHintsProvider
) {
monaco.languages.registerInlayHintsProvider(sandbox.language, createTwoslashInlayProvider(sandbox))
}

Expand Down
21 changes: 16 additions & 5 deletions packages/playground/src/twoslashInlays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export const createTwoslashInlayProvider = (sandbox: Sandbox) => {
const results: import("monaco-editor").languages.InlayHint[] = []
const worker = await sandbox.getWorkerProcess()
if (model.isDisposed()) {
return []
return {
hints: [],
dispose: () => {},
}
}

while ((match = queryRegex.exec(text)) !== null) {
Expand All @@ -18,7 +21,12 @@ export const createTwoslashInlayProvider = (sandbox: Sandbox) => {
const inspectionPos = new sandbox.monaco.Position(endPos.lineNumber - 1, endPos.column)
const inspectionOff = model.getOffsetAt(inspectionPos)

if (cancel.isCancellationRequested) return []
if (cancel.isCancellationRequested) {
return {
hints: [],
dispose: () => {},
}
}

const hint = await worker.getQuickInfoAtPosition("file://" + model.uri.path, inspectionOff)
if (!hint || !hint.displayParts) continue
Expand All @@ -31,12 +39,15 @@ export const createTwoslashInlayProvider = (sandbox: Sandbox) => {
// @ts-ignore
kind: 0,
position: new sandbox.monaco.Position(endPos.lineNumber, endPos.column + 1),
text,
whitespaceBefore: true,
label: text,
Copy link
Contributor Author

@Andarist Andarist Feb 16, 2022

Choose a reason for hiding this comment

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

this commit has changed text to label and also changed the return type of provideInlayHints:
microsoft/vscode@3677cc4

paddingLeft: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this commit has changed whitespaceBefore to paddingLeft:
microsoft/vscode@8ef8933

}
results.push(inlay)
}
return results
return {
hints: results,
dispose: () => {},
}
},
}
return provider
Expand Down
2 changes: 1 addition & 1 deletion packages/sandbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"devDependencies": {
"@types/jest": "^25.1.3",
"jest": "*",
"monaco-editor": "^0.29.1",
"monaco-editor": "^0.32.1",
"monaco-typescript": "^3.7.0",
"ts-jest": "^26.4.4",
"typescript": "*"
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5558,7 +5558,7 @@ __metadata:
"@typescript/sandbox": 0.1.0
esbuild: ^0.13.4
jest: "*"
monaco-editor: ^0.29.1
monaco-editor: ^0.32.1
monaco-typescript: ^3.7.0
typescript: "*"
languageName: unknown
Expand All @@ -5572,7 +5572,7 @@ __metadata:
"@typescript/ata": 0.9.3
"@typescript/vfs": 1.3.5
jest: "*"
monaco-editor: ^0.29.1
monaco-editor: ^0.32.1
monaco-typescript: ^3.7.0
ts-jest: ^26.4.4
typescript: "*"
Expand Down Expand Up @@ -20180,10 +20180,10 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"monaco-editor@npm:^0.29.1":
version: 0.29.1
resolution: "monaco-editor@npm:0.29.1"
checksum: bc1df4f0c026073fdfc5b25487c58eabc82b7341653e75e5a5fa06c7754f823d0751d1eb5f4fb1cc4a0d5d0f1ca801b724b3997e0b5acc942e68358be9d70b71
"monaco-editor@npm:^0.32.1":
version: 0.32.1
resolution: "monaco-editor@npm:0.32.1"
checksum: f63e96fadca3e46ee639c3c7fead95bc03413d4b47d27ffdf5636270e2753c45391e830dd34ae5404004b8fc6a06b50a91d9ae4b593e1fc21cfc20ee00ca98c5
languageName: node
linkType: hard

Expand Down