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


TypeScript TextEdit.insert方法代码示例

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


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

示例1: provideEdits

    provideEdits(document: TextDocument, position: Position, ch: string, options: FormattingOptions, line: TextLine): TextEdit[] {
        // We can have else for the following blocks:
        // if:
        // elif x:
        // for x in y:
        // while x:

        // We need to find a block statement that is less than or equal to this statement block (but not greater)
        for (let lineNumber = position.line - 1; lineNumber >= 0; lineNumber--) {
            const prevLine = document.lineAt(lineNumber);
            const prevLineText = prevLine.text;

            // Oops, we've reached a boundary (like the function or class definition)
            // Get out of here
            if (this.boundaryRegExps.some(value => value.test(prevLineText))) {
                return [];
            }

            const blockRegEx = this.previousBlockRegExps.find(value => value.test(prevLineText));
            if (!blockRegEx) {
                continue;
            }

            const startOfBlockInLine = prevLine.firstNonWhitespaceCharacterIndex;
            if (startOfBlockInLine > line.firstNonWhitespaceCharacterIndex) {
                continue;
            }

            const startPosition = new Position(position.line, 0);
            const endPosition = new Position(position.line, line.firstNonWhitespaceCharacterIndex - startOfBlockInLine);

            if (startPosition.isEqual(endPosition)) {
                // current block cannot be at the same level as a preivous block
                continue;
            }
            if (options.insertSpaces) {
                return [
                    TextEdit.delete(new Range(startPosition, endPosition))
                ];
            }
            else {
                // Delete everything before the block and insert the same characters we have in the previous block
                const prefixOfPreviousBlock = prevLineText.substring(0, startOfBlockInLine);

                const startDeletePosition = new Position(position.line, 0);
                const endDeletePosition = new Position(position.line, line.firstNonWhitespaceCharacterIndex);

                return [
                    TextEdit.delete(new Range(startDeletePosition, endDeletePosition)),
                    TextEdit.insert(startDeletePosition, prefixOfPreviousBlock)
                ];
            }
        }

        return [];
    }
开发者ID:walkoncross,项目名称:pythonVSCode,代码行数:56,代码来源:codeBlockFormatProvider.ts

示例2: apply

	apply(): TextEdit {
		switch (this.action) {
			case EditTypes.EDIT_INSERT:
				return TextEdit.insert(this.start, this.text);
			case EditTypes.EDIT_DELETE:
				return TextEdit.delete(new Range(this.start, this.end));
			case EditTypes.EDIT_REPLACE:
				return TextEdit.replace(new Range(this.start, this.end), this.text);
		}
	}
开发者ID:oliverkofoed,项目名称:vscode-go,代码行数:10,代码来源:util.ts

示例3: transform

export function transform(
	editorconfig: editorconfig.knownProps,
	textDocument: TextDocument
): TextEdit[] {
	const lineCount = textDocument.lineCount;
	const lastLine = textDocument.lineAt(lineCount - 1);

	if (!editorconfig.insert_final_newline
		|| lineCount === 0
		|| lastLine.isEmptyOrWhitespace) {
		return [];
	}

	const position = new Position(lastLine.lineNumber, lastLine.text.length);

	return [
		TextEdit.insert(position, newline(editorconfig))
	];
}
开发者ID:rlugojr,项目名称:editorconfig-vscode,代码行数:19,代码来源:insertFinalNewline.ts

示例4: suite

suite('Else block with if in first line of file', () => {
    suiteSetup(async () => {
        await initialize();
        fs.ensureDirSync(path.dirname(outPythoFilesPath));

        ['elseBlocksFirstLine2.py', 'elseBlocksFirstLine4.py', 'elseBlocksFirstLineTab.py'].forEach(file => {
            const targetFile = path.join(outPythoFilesPath, file);
            if (fs.existsSync(targetFile)) { fs.unlinkSync(targetFile); }
            fs.copySync(path.join(srcPythoFilesPath, file), targetFile);
        });
    });
    suiteTeardown(() => closeActiveWindows());
    teardown(() => closeActiveWindows());

    interface TestCase {
        title: string;
        line: number;
        column: number;
        expectedEdits: vscode.TextEdit[];
        formatOptions: vscode.FormattingOptions;
        filePath: string;
    }
    const TAB = '	';
    const testCases: TestCase[] = [
        {
            title: 'else block with 2 spaces',
            line: 3, column: 7,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(3, 0, 3, 2))
            ],
            formatOptions: { insertSpaces: true, tabSize: 2 },
            filePath: elseBlockFirstLine2OutFilePath
        },
        {
            title: 'else block with 4 spaces',
            line: 3, column: 9,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(3, 0, 3, 4))
            ],
            formatOptions: { insertSpaces: true, tabSize: 4 },
            filePath: elseBlockFirstLine4OutFilePath
        },
        {
            title: 'else block with Tab',
            line: 3, column: 6,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(3, 0, 3, 1)),
                vscode.TextEdit.insert(new vscode.Position(3, 0), '')
            ],
            formatOptions: { insertSpaces: false, tabSize: 4 },
            filePath: elseBlockFirstLineTabOutFilePath
        }
    ];

    testCases.forEach((testCase, index) => {
        test(`${index + 1}. ${testCase.title}`, done => {
            const pos = new vscode.Position(testCase.line, testCase.column);
            testFormatting(testCase.filePath, pos, testCase.expectedEdits, testCase.formatOptions).then(done, done);
        });
    });
});
开发者ID:,项目名称:,代码行数:61,代码来源:


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