-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update 'workbench.action.positronConsole.executeCode' to be used in Q…
…uarto (#3107) * Update 'workbench.action.positronConsole.executeCode' to be used in Quarto * Remove monkeying around with `languageId` * Implement `_executeStatementRangeProvider` command, for extensions to use * Import new command * Fix what command returns (statement range, not range) * Apply suggestions from code review Co-authored-by: Davis Vaughan <[email protected]> Signed-off-by: Julia Silge <[email protected]> * Update return for command --------- Signed-off-by: Julia Silge <[email protected]> Co-authored-by: Davis Vaughan <[email protected]>
- Loading branch information
1 parent
cd93dea
commit 1463261
Showing
4 changed files
with
67 additions
and
14 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/vs/editor/contrib/positronStatementRange/browser/provideStatementRange.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,56 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
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 provideStatementRange( | ||
registry: LanguageFeatureRegistry<languages.StatementRangeProvider>, | ||
model: ITextModel, | ||
position: Position, | ||
token: CancellationToken | ||
): Promise<languages.IStatementRange | undefined> { | ||
|
||
const providers = registry.ordered(model); | ||
|
||
for (const provider of providers) { | ||
try { | ||
const result = await provider.provideStatementRange(model, position, token); | ||
if (result) { | ||
return result; | ||
} | ||
} catch (err) { | ||
onUnexpectedExternalError(err); | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
CommandsRegistry.registerCommand('_executeStatementRangeProvider', 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 provideStatementRange( | ||
languageFeaturesService.statementRangeProvider, | ||
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
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