本文整理匯總了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 [];
}
示例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);
}
}
示例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))
];
}
示例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);
});
});
});