Skip to content

Refactor: readability and performance improvements across the codebase - #33

Merged
DaanV2 merged 1 commit into
mainfrom
copilot/refactor-code-for-readability
Apr 2, 2026
Merged

DaanV2 merged 1 commit into
mainfrom
copilot/refactor-code-for-readability

Conversation

Copilot AI commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Broad readability and performance pass — removes dead code, eliminates duplication, fixes a latent crash, and improves O(n²) hot paths.

Performance

  • commands/commands.ts: replaced stdout += data.toString() accumulation (O(n²)) with Buffer chunk arrays + Buffer.concat() at close (O(n)) — matters for large assembly output

Dead code & duplication

  • view/webview.ts: removed the never-called highlightLine() function; extracted its 5 regex replacements into a shared syntaxHighlight() helper called from createAssemblyLine()
  • env/goenv.ts: added a private selectEnvVar() helper to collapse 5 identical QuickPick methods (~75 lines → ~15 lines):
// Before — repeated verbatim for GOARCH, GOOS, GOARM, GOAMD64, GOMIPS
async selectGoArch(): Promise<void> {
  const config = this.getConfig();
  const result = await vscode.window.showQuickPick(makeItems(GOARCH_VALUES, config.GOARCH), { ... });
  if (result === undefined) return;
  const newConfig = { ...config };
  if (result.label === "default") delete newConfig.GOARCH;
  else newConfig.GOARCH = result.label;
  await this.setConfig(newConfig);
  logger.info("GOARCH set", { GOARCH: newConfig.GOARCH });
}

// After
async selectGoArch(): Promise<void> {
  return this.selectEnvVar("GOARCH", GOARCH_VALUES, { title: "Select GOARCH", placeHolder: "..." });
}

Bug fix

  • assembly/info.ts: bounds guard added to the leading-comment while loop — input with no trailing newline (e.g. "# comment") previously crashed with Cannot read properties of undefined

Minor clarity fixes

  • assembly/content.ts: replaced mutation-inside-filter-predicate anti-pattern with flatMap
  • assembly/info.ts: renamed l → line; removed redundant .trim() on already-trimmed headers
  • documents/tracker.ts: fixed "unsubscripe" typo; added void to intentional fire-and-forget Promise.allSettled()
  • extension.ts: corrected misleading log message on onDidSaveTextDocument ("show assembly" → "file saved, checking for assembly updates")
  • go/symbols.ts: /[\(\)\*]/gim → /[()*]/g — removed unnecessary escaping and inapplicable i/m flags
  • view/webview.ts: removed m flag from single-line comment regex in syntaxHighlight()

@DaanV2
DaanV2 marked this pull request as ready for review April 2, 2026 11:31
@DaanV2
DaanV2 merged commit 2945e67 into main Apr 2, 2026
2 checks passed
@DaanV2
DaanV2 deleted the copilot/refactor-code-for-readability branch April 2, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants