-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new
positron.executeHelpTopicProvider
API command (#5292)
Addresses #4097 Goes together with quarto-dev/quarto#599; the Quarto PR is needed to actually see this work but this PR should be able to be merged on its own. ### QA Notes In a Quarto file, you should be able to use <kbd>F1</kbd> to bring up help for R like so: ![help-quarto](https://github.com/user-attachments/assets/e23c6a23-f0c5-404e-8284-1274c7c66b8b) This is only working right now for R, because of #5290. When we fix that, we should also confirm it works in a `.qmd` as well.
- Loading branch information
1 parent
f2f2279
commit d599f95
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/vs/editor/contrib/positronHelp/browser/provideHelpTopic.ts
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,57 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { LanguageFeatureRegistry } from 'vs/editor/common/languageFeatureRegistry'; | ||
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'; | ||
import * as languages from 'vs/editor/common/languages'; | ||
import { onUnexpectedExternalError } from 'vs/base/common/errors'; | ||
import { CommandsRegistry } from 'vs/platform/commands/common/commands'; | ||
import { assertType } from 'vs/base/common/types'; | ||
import { URI } from 'vs/base/common/uri'; | ||
import { IPosition, Position } from 'vs/editor/common/core/position'; | ||
import { ITextModel } from 'vs/editor/common/model'; | ||
import { IModelService } from 'vs/editor/common/services/model'; | ||
import { CancellationToken } from 'vs/base/common/cancellation'; | ||
|
||
|
||
async function provideHelpTopic( | ||
registry: LanguageFeatureRegistry<languages.HelpTopicProvider>, | ||
model: ITextModel, | ||
position: Position, | ||
token: CancellationToken | ||
): Promise<string | undefined> { | ||
|
||
const providers = registry.ordered(model); | ||
|
||
for (const provider of providers) { | ||
try { | ||
const result = await provider.provideHelpTopic(model, position, token); | ||
if (result) { | ||
return result; | ||
} | ||
} catch (err) { | ||
onUnexpectedExternalError(err); | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
CommandsRegistry.registerCommand('_executeHelpTopicProvider', async (accessor, ...args: [URI, IPosition]) => { | ||
const [uri, position] = args; | ||
assertType(URI.isUri(uri)); | ||
assertType(Position.isIPosition(position)); | ||
|
||
const model = accessor.get(IModelService).getModel(uri); | ||
if (!model) { | ||
return undefined; | ||
} | ||
const languageFeaturesService = accessor.get(ILanguageFeaturesService); | ||
return await provideHelpTopic( | ||
languageFeaturesService.helpTopicProvider, | ||
model, | ||
Position.lift(position), | ||
CancellationToken.None | ||
); | ||
}); |
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