当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript WorkspaceEdit.insert方法代码示例

本文整理汇总了TypeScript中vscode.WorkspaceEdit.insert方法的典型用法代码示例。如果您正苦于以下问题:TypeScript WorkspaceEdit.insert方法的具体用法?TypeScript WorkspaceEdit.insert怎么用?TypeScript WorkspaceEdit.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vscode.WorkspaceEdit的用法示例。


在下文中一共展示了WorkspaceEdit.insert方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: async

		saveText: async (text: string) => {
			const filename = await utils.createFile('', getFixturePath([
				rule,
				value,
				'test'
			]));
			const doc = await workspace.openTextDocument(filename);
			await window.showTextDocument(doc);
			const edit = new WorkspaceEdit();
			edit.insert(doc.uri, new Position(0, 0), text);
			assert.strictEqual(
				await workspace.applyEdit(edit),
				true,
				'applies edit'
			);
			return await new Promise(resolve => {
				let saveCount = 0;
				workspace.onDidSaveTextDocument(savedDoc => {
					if (++saveCount === (options.saves || 1)) {
						resolve(savedDoc.getText());
					}
				});
				doc.save();
			});
		}
开发者ID:SamVerschueren,项目名称:editorconfig-vscode,代码行数:25,代码来源:index.test.ts

示例2: applyUsingWorkspaceEdit

	// Applies Edits to given WorkspaceEdit
	applyUsingWorkspaceEdit(workspaceEdit: WorkspaceEdit, fileUri: Uri): void {
		switch (this.action) {
			case EditTypes.EDIT_INSERT:
				workspaceEdit.insert(fileUri, this.start, this.text);
				break;

			case EditTypes.EDIT_DELETE:
				workspaceEdit.delete(fileUri, new Range(this.start, this.end));
				break;

			case EditTypes.EDIT_REPLACE:
				workspaceEdit.replace(fileUri, new Range(this.start, this.end), this.text);
				break;
		}
	}
开发者ID:leaxoy,项目名称:vscode-go,代码行数:16,代码来源:diffUtils.ts

示例3: createDoc

			return new Promise<string>(async resolve => {
				const doc = await createDoc(options.contents);
				workspace.onDidChangeTextDocument(doc.save);
				workspace.onDidSaveTextDocument(savedDoc => {
					assert.strictEqual(savedDoc.isDirty, false, 'dirty saved doc');
					resolve(savedDoc.getText());
				});
				const edit = new WorkspaceEdit();
				edit.insert(doc.uri, new Position(0, 0), text);
				assert.strictEqual(
					await workspace.applyEdit(edit),
					true,
					'editor fails to apply edit'
				);
			});
开发者ID:jedmao,项目名称:editorconfig-vscode,代码行数:15,代码来源:index.test.ts

示例4: async

		saveText: async (text: string) => {
			const doc = await createDoc();
			const edit = new WorkspaceEdit();
			edit.insert(doc.uri, new Position(0, 0), text);
			assert.strictEqual(
				await workspace.applyEdit(edit),
				true,
				'applies edit'
			);
			return await new Promise(resolve => {
				workspace.onDidSaveTextDocument(savedDoc => {
					resolve(savedDoc.getText());
				});
				doc.save();
			});
		}
开发者ID:rlugojr,项目名称:editorconfig-vscode,代码行数:16,代码来源:index.test.ts

示例5: onDocumentOpen

function onDocumentOpen(td: TextDocument) {
	let extension = extname(td.fileName);
	if (extension != ".wurst" && extension != ".jurst") {
		return;
	}
	if (td.lineCount > 1 || td.getText().length > 0) {
		return;
	}

	let packageName = basename(td.fileName, extension);
	let newText = `package ${packageName}\n\n`;

	let edit = new WorkspaceEdit()
	edit.insert(td.uri, new Position(1,1), newText)
	workspace.applyEdit(edit);


}
开发者ID:peq,项目名称:wurst4vscode,代码行数:18,代码来源:fileCreation.ts

示例6: addNewLine

  public addNewLine(document: TextDocument) {
    // get the line count
    let lineCount = document.lineCount;
    console.log('lineCount: ' + lineCount);

    let allText = document.getText();
    let matches = allText.match(/\r?\n$/);
    if (matches) {
      return;
    }

    let workspaceConfiguration = workspace.getConfiguration('editor');
    let lineEnding: string = workspaceConfiguration.get<string>('lineEnding');

    let uri = document.uri;

    let workspaceEdit = new WorkspaceEdit();
    let position = new Position(lineCount, 0);
    workspaceEdit.insert(uri, position, lineEnding);
    workspace.applyEdit(workspaceEdit).then(function() {
      document.save();
    });
  }
开发者ID:jdforsythe,项目名称:vscode-add-new-line-to-files,代码行数:23,代码来源:extension.ts

示例7: test

  test('jj -> <Esc> through modehandler', async () => {
    const expectedDocumentContent = 'lorem ipsum';

    // setup
    await setupWithBindings({
      insertModeKeyBindings: defaultInsertModeKeyBindings,
      normalModeKeyBindings: defaultNormalModeKeyBindings,
      visualModeKeyBindings: defaultVisualModeKeyBindings,
    });

    let remapper = new Remappers();

    const edit = new vscode.WorkspaceEdit();
    edit.insert(
      vscode.window.activeTextEditor!.document.uri,
      new vscode.Position(0, 0),
      expectedDocumentContent
    );
    vscode.workspace.applyEdit(edit);

    await modeHandler.handleKeyEvent('i');
    assertEqual(modeHandler.currentMode.name, ModeName.Insert);

    // act
    let actual = false;
    try {
      actual = await remapper.sendKey(['j', 'j'], modeHandler, modeHandler.vimState);
    } catch (e) {
      assert.fail(e);
    }

    // assert
    assert.equal(actual, true);
    assertEqual(modeHandler.currentMode.name, ModeName.Normal);
    assert.equal(vscode.window.activeTextEditor!.document.getText(), expectedDocumentContent);
  });
开发者ID:arussellk,项目名称:Vim,代码行数:36,代码来源:remapper.test.ts


注:本文中的vscode.WorkspaceEdit.insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。