MCPcopy Create free account
hub / github.com/REditorSupport/vscode-R / documentNew

Function documentNew

src/rstudioapi.ts:256–279  ·  view source on GitHub ↗
(text: string, type: string, position: number[])

Source from the content-addressed store, hash-verified

254}
255
256export async function documentNew(text: string, type: string, position: number[]): Promise<void> {
257 const currentProjectPath = projectPath().path;
258 if (!currentProjectPath) {
259 return; // TODO: Report failure
260 }
261 const documentUri = Uri.parse('untitled:' + path.join(currentProjectPath, 'new_document.' + type));
262 const targetDocument = await workspace.openTextDocument(documentUri);
263 const edit = new WorkspaceEdit();
264 const docLines = targetDocument.lineCount;
265 edit.replace(documentUri,
266 targetDocument.validateRange(new Range(
267 new Position(0, 0),
268 new Position(docLines + 1, 0)
269 )),
270 text);
271
272 void workspace.applyEdit(edit).then(async () => {
273 const editor = await window.showTextDocument(targetDocument);
274 editor.selections = [new Selection(
275 parsePosition(position, targetDocument),
276 parsePosition(position, targetDocument)
277 )];
278 });
279}
280
281// interface
282// represents addins in a QuickPick menu

Callers 1

dispatchRStudioAPICallFunction · 0.85

Calls 2

projectPathFunction · 0.85
parsePositionFunction · 0.85

Tested by

no test coverage detected