Skip to content
Open
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
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to the "definition-view" extension will be documented in thi

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [0.0.7]
- Fix indentation for preprocessor directives
- Update version to 0.0.7

## [0.0.6]
- Update version to 0.0.6

## [Unreleased]

- Initial release
- Initial release
1 change: 1 addition & 0 deletions media/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ code {
color: inherit;
background: var(--vscode-textCodeBlock-background);
font-family: var(--vscode-editor-font-family);
tab-size: 4;
}

ul,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "definition-view",
"displayName": "Definition View",
"description": "Display full code definition in the sidebar.",
"version": "0.0.6",
"publisher": "stevepryde",
"version": "0.0.7",
"publisher": "unknownprojectx",
"keywords": [
"definition",
"docs",
Expand Down Expand Up @@ -129,4 +129,4 @@
"webpack": "^5.72.0",
"webpack-cli": "^4.9.0"
}
}
}
24 changes: 23 additions & 1 deletion src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ export class Renderer {
if (trimmedLine.length > 0) {
// Keep searching until the next non-blank line that is
// at a shorter indent level.

// Ignore preprocessor directives which are typically at column 0.
// This fixes issues with #if / #endif in C-like languages.
const cStyleLangs = ['c', 'cpp', 'csharp', 'objective-c', 'objective-cpp', 'swift', 'vb'];
if (firstChar === '#' && cStyleLangs.includes(doc.languageId)) {
if (n > lastLine) {
lastLine = n;
}
continue;
}

if (lineIndent < indent) {
break;
} else if (insideBlock && lineIndent === indent) {
Expand Down Expand Up @@ -152,7 +163,18 @@ export class Renderer {
}
}
}
lines = lines.slice(firstLine, lastLine + 1).map((x) => { return x.substring(indent) });
lines = lines.slice(firstLine, lastLine + 1).map((x) => {
if (x.trim().length === 0) {
return '';
}

let lineIndent = x.search(/\S/);
if (lineIndent !== -1 && lineIndent < indent) {
return x.substring(lineIndent);
}

return x.substring(indent);
});
return lines.join("\n") + "\n";
}
}