vscode#FormattingOptions TypeScript Examples
The following examples show how to use
vscode#FormattingOptions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: cfgFormat.ts From sourcepawn-vscode with MIT License | 6 votes |
public provideDocumentFormattingEdits(
document: TextDocument,
options: FormattingOptions,
token: CancellationToken
): ProviderResult<TextEdit[]> {
let workspaceFolder = Workspace.getWorkspaceFolder(document.uri);
// Get the user's settings.
let insertSpaces: boolean =
Workspace.getConfiguration("editor", workspaceFolder).get(
"insertSpaces"
) || false;
let tabSize: number =
Workspace.getConfiguration("editor", workspaceFolder).get("tabSize") || 2;
// Apply user settings
const start = new Position(0, 0);
const end = new Position(
document.lineCount - 1,
document.lineAt(document.lineCount - 1).text.length
);
let range = new Range(start, end);
let text = formatCFGText(document.getText(), insertSpaces, tabSize);
// If process failed,
if (text === "") {
window.showErrorMessage(
"The formatter failed to run, check the console for more details."
);
return undefined;
}
return [new TextEdit(range, text)];
}
Example #2
Source File: extension.ts From vscode-crestron-splus with GNU General Public License v3.0 | 6 votes |
public async provideDocumentRangeFormattingEdits(
document: TextDocument,
range: Range,
_options: FormattingOptions,
_token: CancellationToken
): Promise<TextEdit[]> {
return this.provideEdits(document, {
rangeEnd: document.offsetAt(range.end),
rangeStart: document.offsetAt(range.start),
});
}
Example #3
Source File: spFormat.ts From sourcepawn-vscode with MIT License | 5 votes |
public provideDocumentFormattingEdits(
document: TextDocument,
options: FormattingOptions,
token: CancellationToken
): ProviderResult<TextEdit[]> {
// Get the user's settings.
let insertSpaces: boolean =
Workspace.getConfiguration("editor").get("insertSpaces") || false;
let UseTab: string = insertSpaces ? "Never" : "Always";
let tabSize: number =
Workspace.getConfiguration("editor").get("tabSize") || 2;
let workspaceFolder = Workspace.getWorkspaceFolder(document.uri);
let defaultStyles: string[] =
Workspace.getConfiguration("sourcepawn", workspaceFolder).get(
"formatterSettings"
) || [];
let default_style: string = "{" + defaultStyles.join(", ") + "}";
// Apply user settings
default_style = default_style
.replace(/\${TabSize}/g, tabSize.toString())
.replace(/\${UseTab}/g, UseTab);
const start = new Position(0, 0);
const end = new Position(
document.lineCount - 1,
document.lineAt(document.lineCount - 1).text.length
);
const range = new Range(start, end);
const tempFile = join(__dirname, "temp_format.sp");
let file = openSync(tempFile, "w", 0o765);
writeSync(file, document.getText());
closeSync(file);
let text = this.clangFormat(tempFile, "utf-8", default_style);
// If process failed,
if (text === undefined) {
window.showErrorMessage(
"The formatter failed to run, check the console for more details."
);
return undefined;
}
text = fixFormatting(text);
return [new TextEdit(range, text)];
}
Example #4
Source File: extension.ts From vscode-crestron-splus with GNU General Public License v3.0 | 5 votes |
public async provideDocumentFormattingEdits(
document: TextDocument,
_options: FormattingOptions,
_token: CancellationToken
): Promise<TextEdit[]> {
return this.provideEdits(document);
}