From 4def51456ec50605b709cf01078060817821222e Mon Sep 17 00:00:00 2001 From: UnknownProjectX Date: Mon, 19 Jan 2026 23:01:00 +0800 Subject: [PATCH 1/2] Fix: Indentation issue with preprocessor directives (#if/#endif) --- CHANGELOG.md | 9 ++++++++- package-lock.json | 4 ++-- package.json | 4 ++-- src/renderer.ts | 24 +++++++++++++++++++++++- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f29459e..624502c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 \ No newline at end of file +- Initial release diff --git a/package-lock.json b/package-lock.json index 52cf635..717fc48 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "definition-view", - "version": "0.0.1", + "version": "0.0.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "definition-view", - "version": "0.0.1", + "version": "0.0.6", "dependencies": { "json5": "^2.1.3", "oniguruma": "^7.2.1", diff --git a/package.json b/package.json index ac30797..1e8ddf4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "definition-view", "displayName": "Definition View", "description": "Display full code definition in the sidebar.", - "version": "0.0.6", + "version": "0.0.7", "publisher": "stevepryde", "keywords": [ "definition", @@ -129,4 +129,4 @@ "webpack": "^5.72.0", "webpack-cli": "^4.9.0" } -} \ No newline at end of file +} diff --git a/src/renderer.ts b/src/renderer.ts index 578474e..77139cf 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -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) { @@ -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"; } } From af8d180b32ba415c37541db5a20b1f844db672da Mon Sep 17 00:00:00 2001 From: UnknownProjectX Date: Tue, 20 Jan 2026 10:40:06 +0800 Subject: [PATCH 2/2] Fix: Set tab-size to 4 and update publisher --- media/main.css | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/media/main.css b/media/main.css index 1058c0f..1597838 100644 --- a/media/main.css +++ b/media/main.css @@ -38,6 +38,7 @@ code { color: inherit; background: var(--vscode-textCodeBlock-background); font-family: var(--vscode-editor-font-family); + tab-size: 4; } ul, diff --git a/package.json b/package.json index 1e8ddf4..18dd768 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Definition View", "description": "Display full code definition in the sidebar.", "version": "0.0.7", - "publisher": "stevepryde", + "publisher": "unknownprojectx", "keywords": [ "definition", "docs",