-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a few more OpenRPC methods for rstudioapi shims #2593
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f594a0b
Add `execute_code` OpenRPC method
juliasilge 8df207d
Add `new_document` OpenRPC method
juliasilge ca5ada0
Merge branch 'main' into last-rstudioapi-shims-i-hope
juliasilge be34092
Bump ark to 0.1.75
juliasilge 6c6468f
Merge branch 'main' into last-rstudioapi-shims-i-hope
juliasilge a70393b
Bump ark to 0.1.76 on request from @DavisVaughan
juliasilge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -4,11 +4,13 @@ | |
|
||
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 { ExtHostModalDialogs } from '../positron/extHostModalDialogs'; | ||
import { ExtHostLanguageRuntime } from '../positron/extHostLanguageRuntime'; | ||
import { UiFrontendRequest, EditorContext } from 'vs/workbench/services/languageRuntime/common/positronUiComm'; | ||
import { JsonRpcErrorCode } from 'vs/workbench/services/languageRuntime/common/positronBaseComm'; | ||
import { EndOfLine } from '../extHostTypeConverters'; | ||
import { EndOfLine, TextEditorOpenOptions } from '../extHostTypeConverters'; | ||
|
||
type JsonRpcResponse = JsonRpcResult | JsonRpcError; | ||
|
||
|
@@ -34,7 +36,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 | ||
) { | ||
} | ||
|
@@ -71,6 +75,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') || | ||
|
@@ -95,6 +109,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); | ||
|
@@ -191,10 +219,28 @@ export class ExtHostMethods implements extHostProtocol.ExtHostMethodsShape { | |
return this.dialogs.showSimpleModalDialogMessage(title, message); | ||
} | ||
|
||
async createDocument(contents: string, languageId: string): Promise<null> { | ||
|
||
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; | ||
Comment on lines
+260
to
+261
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For us to address with #2571 |
||
} | ||
|
||
async showQuestion(title: string, message: string, okButtonTitle: string, cancelButtonTitle: string): Promise<boolean> { | ||
return this.dialogs.showSimpleModalDialogPrompt(title, message, okButtonTitle, cancelButtonTitle); | ||
} | ||
|
||
async executeCode(languageId: string, code: string, focus: boolean, allowIncomplete?: boolean): Promise<boolean> { | ||
return this.runtime.executeCode(languageId, code, focus, allowIncomplete); | ||
} | ||
|
||
async debugSleep(ms: number): Promise<null> { | ||
await delay(ms); | ||
return null; | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we address #2438, we can pass a
Range
(i.e. twoPosition
objects) in here in theTextEditorOpenOptions
.