diff --git a/extensions/positron-python/pythonFiles/positron/positron_ipykernel/ui_comm.py b/extensions/positron-python/pythonFiles/positron/positron_ipykernel/ui_comm.py index c21823933fd..2a1d016f98f 100644 --- a/extensions/positron-python/pythonFiles/positron/positron_ipykernel/ui_comm.py +++ b/extensions/positron-python/pythonFiles/positron/positron_ipykernel/ui_comm.py @@ -247,6 +247,20 @@ class OpenEditorParams(BaseModel): ) +class NewDocumentParams(BaseModel): + """ + Create a new document with text contents + """ + + contents: str = Field( + description="Document contents", + ) + + language_id: str = Field( + description="Language identifier", + ) + + class ShowMessageParams(BaseModel): """ Show a message @@ -337,6 +351,28 @@ class ExecuteCommandParams(BaseModel): ) +class ExecuteCodeParams(BaseModel): + """ + Execute code in a Positron runtime + """ + + language_id: str = Field( + description="The language ID of the code to execute", + ) + + code: str = Field( + description="The code to execute", + ) + + focus: bool = Field( + description="Whether to focus the runtime's console", + ) + + allow_incomplete: bool = Field( + description="Whether to bypass runtime code completeness checks", + ) + + class OpenWorkspaceParams(BaseModel): """ Open a workspace @@ -403,6 +439,8 @@ class ShowUrlParams(BaseModel): OpenEditorParams.update_forward_refs() +NewDocumentParams.update_forward_refs() + ShowMessageParams.update_forward_refs() ShowQuestionParams.update_forward_refs() @@ -417,6 +455,8 @@ class ShowUrlParams(BaseModel): ExecuteCommandParams.update_forward_refs() +ExecuteCodeParams.update_forward_refs() + OpenWorkspaceParams.update_forward_refs() SetEditorSelectionsParams.update_forward_refs() diff --git a/extensions/positron-r/package.json b/extensions/positron-r/package.json index 03cc6523c89..3886bb517ff 100644 --- a/extensions/positron-r/package.json +++ b/extensions/positron-r/package.json @@ -533,7 +533,7 @@ }, "positron": { "binaryDependencies": { - "ark": "0.1.74" + "ark": "0.1.76" } } } diff --git a/positron/comms/ui-frontend-openrpc.json b/positron/comms/ui-frontend-openrpc.json index 13e9b703e10..427015d2100 100644 --- a/positron/comms/ui-frontend-openrpc.json +++ b/positron/comms/ui-frontend-openrpc.json @@ -53,6 +53,28 @@ } ] }, + { + "name": "new_document", + "summary": "Create a new document with text contents", + "description": "Use this to create a new document with the given language ID and text contents", + "params": [ + { + "name": "contents", + "description": "Document contents", + "schema": { + "type": "string" + } + }, + { + "name": "language_id", + "description": "Language identifier", + "schema": { + "type": "string" + } + } + ], + "result": {} + }, { "name": "show_message", "summary": "Show a message", @@ -194,6 +216,42 @@ } ] }, + { + "name": "execute_code", + "summary": "Execute code in a Positron runtime", + "description": "Use this to execute code in a Positron runtime", + "params": [ + { + "name": "language_id", + "description": "The language ID of the code to execute", + "schema": { + "type": "string" + } + }, + { + "name": "code", + "description": "The code to execute", + "schema": { + "type": "string" + } + }, + { + "name": "focus", + "description": "Whether to focus the runtime's console", + "schema": { + "type": "boolean" + } + }, + { + "name": "allow_incomplete", + "description": "Whether to bypass runtime code completeness checks", + "schema": { + "type": "boolean" + } + } + ], + "result": {} + }, { "name": "open_workspace", "summary": "Open a workspace", diff --git a/src/vs/workbench/api/common/positron/extHost.positron.api.impl.ts b/src/vs/workbench/api/common/positron/extHost.positron.api.impl.ts index 31425064f37..795cb7557f5 100644 --- a/src/vs/workbench/api/common/positron/extHost.positron.api.impl.ts +++ b/src/vs/workbench/api/common/positron/extHost.positron.api.impl.ts @@ -16,6 +16,7 @@ import * as extHostTypes from 'vs/workbench/api/common/positron/extHostTypes.pos import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService'; import { ExtHostPreviewPanels } from 'vs/workbench/api/common/positron/extHostPreviewPanels'; import { ExtHostModalDialogs } from 'vs/workbench/api/common/positron/extHostModalDialogs'; +import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments'; import { ExtHostContext } from 'vs/workbench/api/common/extHost.protocol'; import { IExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace'; import { ExtHostWebviews } from 'vs/workbench/api/common/extHostWebview'; @@ -57,12 +58,12 @@ export function createPositronApiFactoryAndRegisterActors(accessor: ServicesAcce const extHostLanguageFeatures: ExtHostLanguageFeatures = rpcProtocol.getRaw(ExtHostContext.ExtHostLanguageFeatures); const extHostEditors: ExtHostEditors = rpcProtocol.getRaw(ExtHostContext.ExtHostEditors); - + const extHostDocuments: ExtHostDocuments = rpcProtocol.getRaw(ExtHostContext.ExtHostDocuments); const extHostLanguageRuntime = rpcProtocol.set(ExtHostPositronContext.ExtHostLanguageRuntime, new ExtHostLanguageRuntime(rpcProtocol)); const extHostPreviewPanels = rpcProtocol.set(ExtHostPositronContext.ExtHostPreviewPanel, new ExtHostPreviewPanels(rpcProtocol, extHostWebviews, extHostWorkspace)); const extHostModalDialogs = rpcProtocol.set(ExtHostPositronContext.ExtHostModalDialogs, new ExtHostModalDialogs(rpcProtocol)); const extHostConsoleService = rpcProtocol.set(ExtHostPositronContext.ExtHostConsoleService, new ExtHostConsoleService(rpcProtocol, extHostLogService)); - const extHostMethods = rpcProtocol.set(ExtHostPositronContext.ExtHostMethods, new ExtHostMethods(rpcProtocol, extHostEditors, extHostModalDialogs, extHostWorkspace)); + const extHostMethods = rpcProtocol.set(ExtHostPositronContext.ExtHostMethods, new ExtHostMethods(rpcProtocol, extHostEditors, extHostDocuments, extHostModalDialogs, extHostLanguageRuntime, extHostWorkspace)); return function (extension: IExtensionDescription, extensionInfo: IExtensionRegistries, configProvider: ExtHostConfigProvider): typeof positron { diff --git a/src/vs/workbench/api/common/positron/extHostMethods.ts b/src/vs/workbench/api/common/positron/extHostMethods.ts index 925cee80cf2..38a563302ac 100644 --- a/src/vs/workbench/api/common/positron/extHostMethods.ts +++ b/src/vs/workbench/api/common/positron/extHostMethods.ts @@ -4,12 +4,14 @@ import * as extHostProtocol from './extHost.positron.protocol'; import { ExtHostEditors } from '../extHostTextEditors'; -import { ExtHostModalDialogs } from '../positron/extHostModalDialogs'; +import { ExtHostDocuments } from '../extHostDocuments'; import { ExtHostWorkspace } from '../extHostWorkspace'; -import { Range } from 'vs/workbench/api/common/extHostTypes'; +import { ExtHostModalDialogs } from '../positron/extHostModalDialogs'; +import { ExtHostLanguageRuntime } from '../positron/extHostLanguageRuntime'; import { UiFrontendRequest, EditorContext, Range as UIRange } from 'vs/workbench/services/languageRuntime/common/positronUiComm'; import { JsonRpcErrorCode } from 'vs/workbench/services/languageRuntime/common/positronBaseComm'; -import { EndOfLine } from '../extHostTypeConverters'; +import { Range } from 'vs/workbench/api/common/extHostTypes'; +import { EndOfLine, TextEditorOpenOptions } from '../extHostTypeConverters'; type JsonRpcResponse = JsonRpcResult | JsonRpcError; @@ -35,7 +37,9 @@ export class ExtHostMethods implements extHostProtocol.ExtHostMethodsShape { constructor( _mainContext: extHostProtocol.IMainPositronContext, private readonly editors: ExtHostEditors, + private readonly documents: ExtHostDocuments, private readonly dialogs: ExtHostModalDialogs, + private readonly runtime: ExtHostLanguageRuntime, private readonly workspace: ExtHostWorkspace ) { } @@ -84,6 +88,16 @@ export class ExtHostMethods implements extHostProtocol.ExtHostMethodsShape { result = await this.workspaceFolder(); break; } + case UiFrontendRequest.NewDocument: { + if (!params || + !Object.keys(params).includes('contents') || + !Object.keys(params).includes('language_id')) { + return newInvalidParamsError(method); + } + result = await this.createDocument(params.contents as string, + params.language_id as string); + break; + } case UiFrontendRequest.ShowQuestion: { if (!params || !Object.keys(params).includes('title') || @@ -108,6 +122,20 @@ export class ExtHostMethods implements extHostProtocol.ExtHostMethodsShape { params.message as string); break; } + case UiFrontendRequest.ExecuteCode: { + if (!params || + !Object.keys(params).includes('language_id') || + !Object.keys(params).includes('code') || + !Object.keys(params).includes('focus') || + !Object.keys(params).includes('allow_incomplete')) { + return newInvalidParamsError(method); + } + result = await this.executeCode(params.language_id as string, + params.code as string, + params.focus as boolean, + params.allow_incomplete as boolean); + break; + } case UiFrontendRequest.DebugSleep: { if (!params || !Object.keys(params).includes('ms')) { return newInvalidParamsError(method); @@ -219,10 +247,28 @@ export class ExtHostMethods implements extHostProtocol.ExtHostMethodsShape { return this.dialogs.showSimpleModalDialogMessage(title, message); } + async createDocument(contents: string, languageId: string): Promise { + + const uri = await this.documents.createDocumentData({ + content: contents, language: languageId + }); + const opts: TextEditorOpenOptions = { preview: true }; + this.documents.ensureDocumentData(uri).then(documentData => { + this.editors.showTextDocument(documentData.document, opts); + }); + + // TODO: Return a document ID + return null; + } + async showQuestion(title: string, message: string, okButtonTitle: string, cancelButtonTitle: string): Promise { return this.dialogs.showSimpleModalDialogPrompt(title, message, okButtonTitle, cancelButtonTitle); } + async executeCode(languageId: string, code: string, focus: boolean, allowIncomplete?: boolean): Promise { + return this.runtime.executeCode(languageId, code, focus, allowIncomplete); + } + async debugSleep(ms: number): Promise { await delay(ms); return null; diff --git a/src/vs/workbench/services/languageRuntime/common/positronUiComm.ts b/src/vs/workbench/services/languageRuntime/common/positronUiComm.ts index 6775dcc567c..a58b5e3a73c 100644 --- a/src/vs/workbench/services/languageRuntime/common/positronUiComm.ts +++ b/src/vs/workbench/services/languageRuntime/common/positronUiComm.ts @@ -279,6 +279,25 @@ export interface ShowUrlEvent { } +/** + * Request: Create a new document with text contents + * + * Use this to create a new document with the given language ID and text + * contents + */ +export interface NewDocumentRequest { + /** + * Document contents + */ + contents: string; + + /** + * Language identifier + */ + language_id: string; + +} + /** * Request: Show a question * @@ -338,6 +357,34 @@ export interface DebugSleepRequest { } +/** + * Request: Execute code in a Positron runtime + * + * Use this to execute code in a Positron runtime + */ +export interface ExecuteCodeRequest { + /** + * The language ID of the code to execute + */ + language_id: string; + + /** + * The code to execute + */ + code: string; + + /** + * Whether to focus the runtime's console + */ + focus: boolean; + + /** + * Whether to bypass runtime code completeness checks + */ + allow_incomplete: boolean; + +} + /** * Request: Path to the workspace folder * @@ -388,9 +435,11 @@ export enum UiFrontendEvent { } export enum UiFrontendRequest { + NewDocument = 'new_document', ShowQuestion = 'show_question', ShowDialog = 'show_dialog', DebugSleep = 'debug_sleep', + ExecuteCode = 'execute_code', WorkspaceFolder = 'workspace_folder', ModifyEditorSelections = 'modify_editor_selections', LastActiveEditorContext = 'last_active_editor_context'