Skip to content

Commit

Permalink
Fix: convert fillstruct's output to character offset (microsoft#2611)
Browse files Browse the repository at this point in the history
  • Loading branch information
stdupp committed Apr 19, 2020
1 parent 7d50d75 commit 6c737b3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/goFillStruct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import cp = require('child_process');
import vscode = require('vscode');
import { promptForMissingTool } from './goInstallTools';
import { byteOffsetAt, getBinPath, getFileArchive, getToolsEnvVars } from './util';
import { byteOffsetAt, getBinPath, getFileArchive, getToolsEnvVars, makeMemoizedByteOffsetConverter } from './util';

// Interface for the output from fillstruct
interface GoFillStructOutput {
Expand Down Expand Up @@ -78,14 +78,15 @@ function execFillStruct(editor: vscode.TextEditor, args: string[]): Promise<void
}

const indent = '\t'.repeat(tabsCount);
const offsetConverter = makeMemoizedByteOffsetConverter(Buffer.from(editor.document.getText()));

editor
.edit((editBuilder) => {
output.forEach((structToFill) => {
const out = structToFill.code.replace(/\n/g, '\n' + indent);
const rangeToReplace = new vscode.Range(
editor.document.positionAt(structToFill.start),
editor.document.positionAt(structToFill.end)
editor.document.positionAt(offsetConverter(structToFill.start)),
editor.document.positionAt(offsetConverter(structToFill.end))
);
editBuilder.replace(rangeToReplace, out);
});
Expand Down

0 comments on commit 6c737b3

Please sign in to comment.