當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。