Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Commit

Permalink
Use FormattingOptions to properly indent
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinrobot committed Sep 9, 2019
1 parent f3ffb4e commit f0c3b12
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ function getEndOfLine() {
return isValid ? endOfLine : "\n";
}

function getIndentation() {
var insertSpaces = getSettings<boolean>("editor", "insertSpaces", false);
if (!insertSpaces) return "\t";
var tabSize = getSettings<number>("editor", "tabSize", 4);
if (typeof tabSize !== "number" || tabSize < 1) tabSize = 4;
function getIndentation(options) {
if (!options.insertSpaces) return "\t";
var tabSize = options.tabSize;
if (tabSize < 1) tabSize = 4;
return " ".repeat(tabSize);
}

export function getConfig() {
const indentation = getIndentation();
export function getConfig(options: vscode.FormattingOptions): VHDLFormatter.BeautifierSettings {
if (!options) options = { insertSpaces: false, tabSize: 4 };

const indentation = getIndentation(options);
const endOfLine = getEndOfLine();

const removeComments = getExtSettings<boolean>(CONFIGURATION_REMOVE_COMMENTS, false);
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ function getDocumentRange(document: vscode.TextDocument) {

export function activate(context: vscode.ExtensionContext) {
vscode.languages.registerDocumentFormattingEditProvider('vhdl', {
provideDocumentFormattingEdits(document: vscode.TextDocument): vscode.TextEdit[] {
provideDocumentFormattingEdits(document: vscode.TextDocument, options: vscode.FormattingOptions): vscode.TextEdit[] {
var range = getDocumentRange(document);
var content = document.getText(range);
var result: vscode.TextEdit[] = [];
var beautifierSettings = config.getConfig();
var beautifierSettings = config.getConfig(options);
var formatted = VHDLFormatter.beautify(content, beautifierSettings);
if (formatted) {
result.push(new vscode.TextEdit(range, formatted));
Expand Down

0 comments on commit f0c3b12

Please sign in to comment.