Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Commit

Permalink
fix sorting imports also using comments
Browse files Browse the repository at this point in the history
  • Loading branch information
WebFreak001 committed Dec 13, 2019
1 parent 4197e76 commit 40baa0d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions source/workspaced/com/importer.d
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ class ImporterComponent : ComponentWrapper
acc += line.length;
}

// go back to start of line
start = code[0 .. start].lastIndexOf('\n', start) + 1;

part = code[start .. end];

auto tokens = getTokensForParser(cast(ubyte[]) part, config, &workspaced.stringCache);
Expand Down Expand Up @@ -356,6 +359,35 @@ import std.algorithm;
ImportInfo(["std", "algorithm"]),
ImportInfo(["std", "traits"])
]));

// ----------------

code = `void foo()
{
// import std.algorithm;
// import std.array;
import std.path;
import std.file;
}`;

assertEqual(backend.get!ImporterComponent(workspace.directory).sortImports(code, 70), ImportBlock(62, 96, [
ImportInfo(["std", "file"]),
ImportInfo(["std", "path"])
], "\t"));

code = `void foo()
{
/*
import std.algorithm;
import std.array; */
import std.path;
import std.file;
}`;

assertEqual(backend.get!ImporterComponent(workspace.directory).sortImports(code, 75), ImportBlock(63, 97, [
ImportInfo(["std", "file"]),
ImportInfo(["std", "path"])
], "\t"));
//dfmt on
}

Expand Down

0 comments on commit 40baa0d

Please sign in to comment.