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


TypeScript TextEdit.replace方法代码示例

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


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

示例1: constructor

	constructor(
		public position: Position,
		public document: TextDocument,
		entry: CompletionEntry,
		enableDotCompletions: boolean,
		enableCallCompletions: boolean
	) {
		super(entry.name);
		this.sortText = entry.sortText;
		this.kind = MyCompletionItem.convertKind(entry.kind);
		this.position = position;
		this.commitCharacters = MyCompletionItem.getCommitCharacters(enableDotCompletions, enableCallCompletions, entry.kind);
		if (entry.replacementSpan) {
			let span: protocol.TextSpan = entry.replacementSpan;
			// The indexing for the range returned by the server uses 1-based indexing.
			// We convert to 0-based indexing.
			this.textEdit = TextEdit.replace(tsTextSpanToVsRange(span), entry.name);
		} else {
			// Try getting longer, prefix based range for completions that span words
			const wordRange = document.getWordRangeAtPosition(position);
			const text = document.getText(new Range(position.line, Math.max(0, position.character - entry.name.length), position.line, position.character)).toLowerCase();
			const entryName = entry.name.toLowerCase();
			for (let i = entryName.length; i >= 0; --i) {
				if (text.endsWith(entryName.substr(0, i)) && (!wordRange || wordRange.start.character > position.character - i)) {
					this.range = new Range(position.line, Math.max(0, position.character - i), position.line, position.character);
					break;
				}
			}
		}
	}
开发者ID:leonardovilarinho,项目名称:vscode,代码行数:30,代码来源:completionItemProvider.ts

示例2: initCompletionProvider

	function initCompletionProvider(): Disposable {
		const regionCompletionRegExpr = /^(\s*)(\/(\*\s*(#\w*)?)?)?$/;

		return languages.registerCompletionItemProvider(documentSelector, {
			provideCompletionItems(doc, pos) {
				let lineUntilPos = doc.getText(new Range(new Position(pos.line, 0), pos));
				let match = lineUntilPos.match(regionCompletionRegExpr);
				if (match) {
					let range = new Range(new Position(pos.line, match[1].length), pos);
					let beginProposal = new CompletionItem('#region', CompletionItemKind.Snippet);
					beginProposal.range = range; TextEdit.replace(range, '/* #region */');
					beginProposal.insertText = new SnippetString('/* #region $1*/');
					beginProposal.documentation = localize('folding.start', 'Folding Region Start');
					beginProposal.filterText = match[2];
					beginProposal.sortText = 'za';
					let endProposal = new CompletionItem('#endregion', CompletionItemKind.Snippet);
					endProposal.range = range;
					endProposal.insertText = '/* #endregion */';
					endProposal.documentation = localize('folding.end', 'Folding Region End');
					endProposal.sortText = 'zb';
					endProposal.filterText = match[2];
					return [beginProposal, endProposal];
				}
				return null;
			}
		});
	}
开发者ID:AllureFer,项目名称:vscode,代码行数:27,代码来源:cssMain.ts

示例3:

			add: (suggestion: CompletionItem) => {
				if (!proposed[suggestion.label]) {
					proposed[suggestion.label] = true;
					suggestion.textEdit = TextEdit.replace(overwriteRange, suggestion.insertText);
					suggestion.filterText = filterText;

					items.push(suggestion);
				}
			},
开发者ID:Aarushi-Ign,项目名称:vscode,代码行数:9,代码来源:jsonContributions.ts

示例4:

			add: (suggestion: vscode.CompletionItem) => {
				if (!proposed[suggestion.label]) {
					proposed[suggestion.label] = true;
					if (overwriteRange) {
						suggestion.textEdit = vscode.TextEdit.replace(overwriteRange, suggestion.insertText);
					}

					items.push(suggestion);
				}
			},
开发者ID:claudiug,项目名称:code-d,代码行数:10,代码来源:json-contributions.ts

示例5: 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

示例6: activate

export function activate(context: vscode.ExtensionContext) {
    console.log('Congratulations, your extension "sql Formatter" is now active!');

    let sqlFormatter  = new sqlFormatterClass();

    vscode.languages.registerDocumentFormattingEditProvider('sql', {
        provideDocumentFormattingEdits(document: vscode.TextDocument): vscode.TextEdit[] {
            let data = sqlFormatter.formatter();
            return [vscode.TextEdit.replace(new Range(data.start, data.end), data.text)];
        }
    });
}
开发者ID:donyang,项目名称:SqlFormatter-VSCode,代码行数:12,代码来源:extension.ts

示例7:

 newIndents.forEach((indent, line) => {
     let oldIndent = oldIndents[line];
     let newIndent = ' '.repeat(indent);
     if (oldIndent !== newIndent) {
         edits.push(vscode.TextEdit.replace(
             new vscode.Range(
                 new vscode.Position(line, 0),
                 new vscode.Position(line, oldIndent.length)
             ),
             newIndent)
         );
     }
 });
开发者ID:let-def,项目名称:vscode-ocaml,代码行数:13,代码来源:extension.ts

示例8: _provideFormattingEdits

 private _provideFormattingEdits(document: vsc.TextDocument, range: vsc.Range, options: vsc.FormattingOptions): vsc.TextEdit[] {
     let splitNamespaces: boolean = vsc.workspace.getConfiguration(CFG_SECTION).get<boolean>(CFG_SPLIT_NAMESPACES, true);
     
     let formatterOptions: IXmlFormatterOptions = {
         preferSpaces: options.insertSpaces,
         tabSize: options.tabSize,
         splitNamespaces: splitNamespaces
     };
     
     let formatter = new XmlFormatter(formatterOptions);
     let xml = formatter.format(document.getText(range));
     
     return [ vsc.TextEdit.replace(range, xml) ];
 }
开发者ID:blastdan,项目名称:vscode-xml,代码行数:14,代码来源:Formatting.ts

示例9: provideFormattingEdits

    private provideFormattingEdits(document: vscode.TextDocument, range: vscode.Range, options: vscode.FormattingOptions): vscode.TextEdit[] {

        this.formatterOptions = {
            tabSize: options.tabSize,
            insertSpaces: options.insertSpaces
        };

        // format as html
        let doc = lst.TextDocument.create(document.uri.fsPath, 'html', 1, document.getText());
        let htmlTextEdit = service.format(doc, range, options);

        // format as blade
        let formatter = new BladeFormatter(this.formatterOptions);
        let bladeText = formatter.format(htmlTextEdit[0].newText);

        return [vscode.TextEdit.replace(range, bladeText)];
    }
开发者ID:onecentlin,项目名称:laravel-blade-snippets-vscode,代码行数:17,代码来源:BladeFormattingEditProvider.ts

示例10: onSave

    public onSave(e: vscode.TextDocumentWillSaveEvent) {
        var { document } = e;
        var docType: Array<string> = ['css', 'scss', 'javascript', 'html', 'json']
        var global = path.join(__dirname, 'formatter.json');
        var local = path.join(getRootPath(), '.vscode', 'formatter.json');
        var onSave;

        try {
            onSave = require(local).onSave;
        } catch (error) {
            try {
                onSave = require(global).onSave;
            } catch (error) {
                onSave = true;
            }
        }

        if (!onSave) {
            return;
        }
        if (docType.indexOf(document.languageId) == -1) {
            return;
        }


        var start = new vscode.Position(0, 0);
        var end = new vscode.Position(document.lineCount - 1, document.lineAt(document.lineCount - 1).text.length);
        var range = new vscode.Range(start, end);

        var result: vscode.TextEdit[] = [];

        var content = document.getText(range);

        var formatted = beatify(content, document.languageId);

        if (formatted) {
            var start = new vscode.Position(0, 0);
            var end = new vscode.Position(document.lineCount - 1, document.lineAt(document.lineCount - 1).text.length);
            range = new vscode.Range(start, end);
            var edit = vscode.TextEdit.replace(range, formatted);
            e.waitUntil(Promise.resolve([edit]));
        }

    }
开发者ID:Lonefy,项目名称:vscode-JS-CSS-HTML-formatter,代码行数:44,代码来源:extension.ts


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