Skip to content

Commit

Permalink
fix: hover markdown links in codespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdabbs committed Jun 5, 2024
1 parent 113e67d commit 53b3c7c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Utilities for viewing and editing the π-base data repository in VSCode.

## Publishing

Run `pnpm publish` to publish. (`prepublish` handles bundling with `pnpm`, which is otherwise unsupported by `vsce`.)
Run `pnpm run publish` to publish. (`prepublish` handles bundling with `pnpm`, which is otherwise unsupported by `vsce`.)

<!--TODO
## Features
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"homepage": "https://topology.pi-base.org/",
"license": "ISC",
"author": "James Dabbs <james.dabbs@gmail.com> (https://jdabbs.com)",
"version": "0.0.13",
"version": "0.0.16",
"repository": {
"type": "git",
"url": "https://github.com/pi-base/web.git"
Expand Down
8 changes: 7 additions & 1 deletion packages/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ import { EntityIdHoverProvider } from './providers/EntityIdHoverProvider'
import { EntityIdLinkProvider } from './providers/EntityIdLinkProvider'
import { ExternalLinkProvider } from './providers/ExternalLinkProvider'
import { setupDecorationProvider } from './providers/decorationProvider'
import debug from 'debug'

export function activate(context: vscode.ExtensionContext) {
findRootFolder().then(uri => {
if (uri) {
setup(context, uri)
try {
debug('Initializing π-base extension')
setup(context, uri)
} catch (error) {
console.error('Failed to initialize π-base extension', error)
}
} else {
console.log(
'No data folder found in workspace. Skipping π-base initialization.',
Expand Down
21 changes: 16 additions & 5 deletions packages/vscode/src/providers/EntityIdHoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@ export class EntityIdHoverProvider

const { uri, name, description } = entity

return new vscode.Hover(
new vscode.MarkdownString(
[`# [${name}](${uri})`, '', description].join('\n'),
),
)
// Hover text only supports an allow list of schemes (https://github.com/microsoft/vscode/issues/153277), which
// doesn't include the `vscode-vfs` scheme used by github.dev, so we instead use a command link to open the file.
//
// See also
// - https://code.visualstudio.com/api/extension-guides/command
// - https://code.visualstudio.com/api/references/commands
const openCommand = `command:vscode.open?${encodeURIComponent(
JSON.stringify([uri]),
)}`
const nameLink = new vscode.MarkdownString(`# [${name}](${openCommand})`)
nameLink.isTrusted = true

return new vscode.Hover([
nameLink,
new vscode.MarkdownString(`\n\n${description}`),
])
}
}

0 comments on commit 53b3c7c

Please sign in to comment.