Skip to content

Commit 6e7370b

Browse files
committed
Small cleanup.
1 parent 2c5fb50 commit 6e7370b

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

server/src/server.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -460,17 +460,9 @@ function format(msg: p.RequestMessage): Array<m.Message> {
460460
};
461461
return [fakeSuccessResponse, response];
462462
} else {
463-
// See comment on findBscNativeDirOfFile for why we need
464-
// to recursively search for bsc.exe upward
465-
let bscNativePath = utils.findBscNativeOfFile(filePath);
466-
467463
// code will always be defined here, even though technically it can be undefined
468464
let code = getOpenedFileContent(params.textDocument.uri);
469-
let formattedResult = utils.formatCode(
470-
code,
471-
bscNativePath,
472-
extension === c.resiExt
473-
);
465+
let formattedResult = utils.formatCode(filePath, code);
474466
if (formattedResult.kind === "success") {
475467
let max = code.length;
476468
let result: p.TextEdit[] = [

server/src/utils.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,17 @@ type execResult =
9393
kind: "error";
9494
error: string;
9595
};
96-
export let formatCode = (
97-
code: string,
98-
bscNativePath: p.DocumentUri | null,
99-
isInterface: boolean
100-
): execResult => {
101-
let extension = isInterface ? c.resiExt : c.resExt;
96+
export let formatCode = (filePath: string, code: string): execResult => {
97+
let extension = path.extname(filePath);
10298
let formatTempFileFullPath = createFileInTempDir(extension);
10399
fs.writeFileSync(formatTempFileFullPath, code, {
104100
encoding: "utf-8",
105101
});
106102
try {
103+
// See comment on findBscNativeDirOfFile for why we need
104+
// to recursively search for bsc.exe upward
105+
let bscNativePath = findBscNativeOfFile(filePath);
106+
107107
// Default to using the project formatter. If not, use the one we ship with
108108
// the analysis binary in the extension itself.
109109
if (bscNativePath != null) {
@@ -128,10 +128,7 @@ export let formatCode = (
128128
// sources, probably because of errors. In that case, we bail from
129129
// formatting by returning the unformatted content.
130130
if (result === "") {
131-
return {
132-
kind: "success",
133-
result: code,
134-
};
131+
result = code;
135132
}
136133

137134
return {

0 commit comments

Comments
 (0)