mirror of https://github.com/buggins/dlangide.git
Added syntax highlighting to search results
This commit is contained in:
parent
4178d63229
commit
d6cffd4e2e
|
@ -12,6 +12,65 @@ import dlangide.workspace.project;
|
||||||
import std.string;
|
import std.string;
|
||||||
import std.conv;
|
import std.conv;
|
||||||
|
|
||||||
|
class SearchLogWidget : LogWidget {
|
||||||
|
|
||||||
|
this(string ID){
|
||||||
|
super(ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
override protected CustomCharProps[] handleCustomLineHighlight(int line, dstring txt, ref CustomCharProps[] buf) {
|
||||||
|
uint defColor = textColor;
|
||||||
|
const uint filenameColor = 0x0000C0;
|
||||||
|
const uint errorColor = 0xFF0000;
|
||||||
|
const uint warningColor = 0x606000;
|
||||||
|
const uint deprecationColor = 0x802040;
|
||||||
|
uint flags = 0;
|
||||||
|
if (buf.length < txt.length)
|
||||||
|
buf.length = txt.length;
|
||||||
|
if(txt.startsWith("Matches in ")) {
|
||||||
|
CustomCharProps[] colors = buf[0..txt.length];
|
||||||
|
uint cl = defColor;
|
||||||
|
flags = 0;
|
||||||
|
for (int i = 0; i < txt.length; i++) {
|
||||||
|
dstring rest = txt[i..$];
|
||||||
|
if(i == 11) {
|
||||||
|
cl = filenameColor;
|
||||||
|
flags = TextFlag.Underline;
|
||||||
|
}
|
||||||
|
colors[i].color = cl;
|
||||||
|
colors[i].textFlags = flags;
|
||||||
|
}
|
||||||
|
return colors;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
CustomCharProps[] colors = buf[0..txt.length];
|
||||||
|
uint cl = filenameColor;
|
||||||
|
flags = TextFlag.Underline;
|
||||||
|
for (int i = 0; i < txt.length; i++) {
|
||||||
|
dstring rest = txt[i..$];
|
||||||
|
if (rest.startsWith(" -->"d)) {
|
||||||
|
cl = warningColor;
|
||||||
|
flags = 0;
|
||||||
|
}
|
||||||
|
if(i == 4) {
|
||||||
|
cl = errorColor;
|
||||||
|
flags = TextFlag.Underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
colors[i].color = cl;
|
||||||
|
colors[i].textFlags = flags;
|
||||||
|
|
||||||
|
//Colors to applay after current character.
|
||||||
|
if(rest.startsWith("]")) {
|
||||||
|
cl = defColor;
|
||||||
|
flags = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return colors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class SearchWidget : TabWidget {
|
class SearchWidget : TabWidget {
|
||||||
HorizontalLayout _layout;
|
HorizontalLayout _layout;
|
||||||
EditLine _findText;
|
EditLine _findText;
|
||||||
|
@ -22,13 +81,14 @@ class SearchWidget : TabWidget {
|
||||||
struct SearchMatch {
|
struct SearchMatch {
|
||||||
int line;
|
int line;
|
||||||
long col;
|
long col;
|
||||||
string fileName;
|
dstring lineContent;
|
||||||
|
|
||||||
string toString() {
|
|
||||||
return '[' ~ to!string(line) ~ ':' ~ to!string(col) ~ "] " ~ fileName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct SearchMatchList {
|
||||||
|
string filename;
|
||||||
|
SearchMatch[] matches;
|
||||||
|
}
|
||||||
|
|
||||||
this(string ID, IDEFrame frame) {
|
this(string ID, IDEFrame frame) {
|
||||||
super(ID);
|
super(ID);
|
||||||
_frame = frame;
|
_frame = frame;
|
||||||
|
@ -52,61 +112,58 @@ class SearchWidget : TabWidget {
|
||||||
_layout.addChild(goButton);
|
_layout.addChild(goButton);
|
||||||
addChild(_layout);
|
addChild(_layout);
|
||||||
|
|
||||||
_resultLog = new LogWidget("SearchLogWidget");
|
_resultLog = new SearchLogWidget("SearchLogWidget");
|
||||||
_resultLog.layoutHeight(FILL_PARENT);
|
_resultLog.layoutHeight(FILL_PARENT);
|
||||||
addChild(_resultLog);
|
addChild(_resultLog);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void searchInProject(ProjectItem project, ref SearchMatch[] matches, dstring text) {
|
void searchInProject(ProjectItem project, ref SearchMatchList[] matchList, dstring text) {
|
||||||
if(project.isFolder) {
|
if(project.isFolder) {
|
||||||
foreach(ProjectItem child; cast(ProjectFolder) project) {
|
foreach(ProjectItem child; cast(ProjectFolder) project) {
|
||||||
searchInProject(child, matches, text);
|
searchInProject(child, matchList, text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
EditableContent content = new EditableContent(true);
|
EditableContent content = new EditableContent(true);
|
||||||
content.load(project.filename);
|
content.load(project.filename);
|
||||||
|
SearchMatchList match;
|
||||||
|
match.filename = project.filename;
|
||||||
|
|
||||||
foreach(int lineIndex, dstring line; content.lines) {
|
foreach(int lineIndex, dstring line; content.lines) {
|
||||||
auto colIndex = line.indexOf(text);
|
auto colIndex = line.indexOf(text);
|
||||||
if( colIndex != -1) {
|
if( colIndex != -1) {
|
||||||
matches ~= SearchMatch(lineIndex+1, colIndex, project.filename);
|
match.matches ~= SearchMatch(lineIndex+1, colIndex, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(match.matches.length > 0) {
|
||||||
|
matchList ~= match;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool findText(dstring source) {
|
bool findText(dstring source) {
|
||||||
Log.d("Finding " ~ source);
|
Log.d("Finding " ~ source);
|
||||||
SearchMatch[] matches;
|
SearchMatchList[] matches;
|
||||||
//TODO Should not crash when in homepage.
|
//TODO Should not crash when in homepage.
|
||||||
|
|
||||||
searchInProject(_frame.currentEditor.projectSourceFile, matches, source);
|
foreach(Project project; _frame._wsPanel.workspace.projects) {
|
||||||
Log.d("Searching in current file " ~ source);
|
searchInProject(project.items, matches, source);
|
||||||
|
|
||||||
if(currentWorkspace) {
|
|
||||||
foreach(ProjectItem project ; currentWorkspace.projects[0].items) {
|
|
||||||
searchInProject(project, matches, source);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(matches.length == 0) {
|
if(matches.length == 0) {
|
||||||
_resultLog.appendText(to!dstring("No matches in current file." ~ '\n'));
|
_resultLog.appendText(to!dstring("No matches found.\n"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_resultLog.appendText(to!dstring("Matches found in current file: " ~ '\n'));
|
foreach(SearchMatchList fileMatchList; matches) {
|
||||||
foreach(SearchMatch match; matches) {
|
_resultLog.appendText("Matches in "d ~ to!dstring(fileMatchList.filename) ~ '\n');
|
||||||
if(match.fileName == _frame.currentEditor.content.filename)
|
foreach(SearchMatch match; fileMatchList.matches) {
|
||||||
_resultLog.appendText(to!dstring(" --> [" ~ to!string(match.line) ~ ':' ~ to!string(match.col) ~ "] in current file\n"));
|
_resultLog.appendText(" --> ["d ~ to!dstring(match.line) ~ ":"d ~ to!dstring(match.col) ~ "]" ~ match.lineContent ~"\n"d);
|
||||||
else
|
}
|
||||||
_resultLog.appendText(to!dstring(" --> " ~ match.toString" ~ '\n'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue