Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)\

## Unreleased

### Changed

- Reads indentation preferences for current workspace and uses it in instantiate module

### Fixed

- Fix by reading preferences from workspace [#493](https://github.com/mshr-h/vscode-verilog-hdl-support/issues/493)

## [1.15.1] - 2024-08-31

### Changed
Expand Down
18 changes: 17 additions & 1 deletion src/commands/ModuleInstantiation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
}
module = modules.filter((tag) => tag.name === moduleName)[0];
}
let scope = module.parentScope != '' ? module.parentScope + '.' + module.name : module.name;

Check warning on line 51 in src/commands/ModuleInstantiation.ts

View workflow job for this annotation

GitHub Actions / Upload vsix package (macos-latest)

Expected '!==' and instead saw '!='

Check warning on line 51 in src/commands/ModuleInstantiation.ts

View workflow job for this annotation

GitHub Actions / Upload vsix package (ubuntu-latest)

Expected '!==' and instead saw '!='

Check warning on line 51 in src/commands/ModuleInstantiation.ts

View workflow job for this annotation

GitHub Actions / Upload vsix package (windows-latest)

Expected '!==' and instead saw '!='
let ports: Symbol[] = ctags.symbols.filter(
(tag) => tag.type === 'port' && tag.parentType === 'module' && tag.parentScope === scope
);
Expand All @@ -73,9 +73,24 @@
.appendText(');\n');
}

function getIndentationString(): string {
const editorConfig = vscode.workspace.getConfiguration('editor');

const useSpaces = editorConfig.get<boolean>('insertSpaces', true);
const tabSize = editorConfig.get<number>('tabSize', 4);

if (useSpaces) {
return ' '.repeat(tabSize);
} else {
return '\t';
}
}

function instantiatePort(ports: string[]): string {
let port = '';
let maxLen = 0;
let indent = getIndentationString();

for (let i = 0; i < ports.length; i++) {
if (ports[i].length > maxLen) {
maxLen = ports[i].length;
Expand All @@ -86,7 +101,8 @@
let element = ports[i];
let padding = maxLen - element.length + 1;
element = element + ' '.repeat(padding);
port += `\t.${element}(${element})`;
port += indent;
port += `.${element}(${element})`;
if (i !== ports.length - 1) {
port += ',';
}
Expand Down
Loading