Skip to content

Commit 7846d86

Browse files
committed
Reads and uses workspace indentation
1 parent 89249ab commit 7846d86

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/commands/ModuleInstantiation.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,24 @@ async function instantiateModule(srcpath: string): Promise<vscode.SnippetString
7373
.appendText(');\n');
7474
}
7575

76+
function getIndentationString(): string {
77+
const editorConfig = vscode.workspace.getConfiguration('editor');
78+
79+
const useSpaces = editorConfig.get<boolean>('insertSpaces', true);
80+
const tabSize = editorConfig.get<number>('tabSize', 4);
81+
82+
if (useSpaces) {
83+
return ' '.repeat(tabSize);
84+
} else {
85+
return '\t';
86+
}
87+
}
88+
7689
function instantiatePort(ports: string[]): string {
7790
let port = '';
7891
let maxLen = 0;
92+
let indent = getIndentationString();
93+
7994
for (let i = 0; i < ports.length; i++) {
8095
if (ports[i].length > maxLen) {
8196
maxLen = ports[i].length;
@@ -86,7 +101,8 @@ function instantiatePort(ports: string[]): string {
86101
let element = ports[i];
87102
let padding = maxLen - element.length + 1;
88103
element = element + ' '.repeat(padding);
89-
port += `\t.${element}(${element})`;
104+
port += indent;
105+
port += `.${element}(${element})`;
90106
if (i !== ports.length - 1) {
91107
port += ',';
92108
}

0 commit comments

Comments
 (0)