diff --git a/src/vs/editor/contrib/positronHelp/browser/provideHelpTopic.ts b/src/vs/editor/contrib/positronHelp/browser/provideHelpTopic.ts new file mode 100644 index 00000000000..094ad3529c2 --- /dev/null +++ b/src/vs/editor/contrib/positronHelp/browser/provideHelpTopic.ts @@ -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, + model: ITextModel, + position: Position, + token: CancellationToken +): Promise { + + 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 + ); +}); diff --git a/src/vs/editor/editor.all.ts b/src/vs/editor/editor.all.ts index b8650497f32..9b9e93ef729 100644 --- a/src/vs/editor/editor.all.ts +++ b/src/vs/editor/editor.all.ts @@ -67,6 +67,7 @@ import 'vs/editor/contrib/diffEditorBreadcrumbs/browser/contribution'; // --- Start Positron --- import 'vs/editor/contrib/positronEditorActions/browser/positronEditorActions'; import 'vs/editor/contrib/positronStatementRange/browser/provideStatementRange'; +import 'vs/editor/contrib/positronHelp/browser/provideHelpTopic'; // --- End Positron --- // Load up these strings even in VSCode, even if they are not used diff --git a/src/vs/workbench/api/common/extHostApiCommands.ts b/src/vs/workbench/api/common/extHostApiCommands.ts index 7ef5e410fe4..03c8e52d1ab 100644 --- a/src/vs/workbench/api/common/extHostApiCommands.ts +++ b/src/vs/workbench/api/common/extHostApiCommands.ts @@ -527,6 +527,14 @@ const newCommands: ApiCommand[] = [ return { range: typeConverters.Range.to(result.range), code: result.code }; }) ), + // -- show help topic + new ApiCommand( + 'positron.executeHelpTopicProvider', '_executeHelpTopicProvider', 'Execute help topic provider.', + [ApiCommandArgument.Uri, ApiCommandArgument.Position], + new ApiCommandResult('A promise that resolves to a string.', result => { + return result; + }) + ), // --- End Positron // --- context keys