-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use of DCD for "Go To Definition" and Code Completion functionality plus other changes. #29
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d766508
Initial implementation of "Go to definition".
Freakazo e098443
Implementated getting completion suggestions.
Freakazo 56ac7b9
Added popup to show completion suggestions. issue #20
Freakazo 0b01ca2
Add navigation menu item and remove toolbar items.
Freakazo ec9b0a2
Insert completion suggestion. issue #20
Freakazo 6b5e307
Send the editor content instead of the file name to dcd
Freakazo 0b026d2
merge with master
Freakazo 317749b
revert change in findPairedBracket, set max height to completion popu…
Freakazo 2b438dd
Set focus on completion popup to allow for arrow key selection of com…
Freakazo 0ebdc67
Add autocomplete to editor popup and added Show Completions translation
Freakazo 7365170
Moved SimpleDSyntaxHighlighter class out of dsourceedit
Freakazo 747cb61
Cleaned up Go To Definition implemention
Freakazo 158d1f1
Cleaned up Show completions
Freakazo 7d59862
Removed unused function
Freakazo bea3c5e
renamed files to fit style guidelines
Freakazo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module dlangide.tools.editorTool; | ||
|
||
|
||
|
||
import dlangui.widgets.editors; | ||
import dlangui.core.types; | ||
import dlangide.ui.frame; | ||
import dlangide.ui.dsourceedit; | ||
|
||
public import dlangide.tools.d.editorTool; | ||
|
||
class EditorTool | ||
{ | ||
this(IDEFrame frame) { | ||
_frame = frame; | ||
} | ||
//Since files might be unsaved, we must send all the text content. | ||
abstract bool goToDefinition(DSourceEdit editor, TextPosition caretPosition); | ||
abstract dstring[] getCompletions(DSourceEdit editor, TextPosition caretPosition); | ||
|
||
protected IDEFrame _frame; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module dlangide.tools.d.DCDInterface; | ||
|
||
import dlangide.builders.extprocess; | ||
|
||
//Interface to DCD | ||
//TODO: Check if server is running, start server if needed etc. | ||
class DCDInterface { | ||
ExternalProcess dcdProcess; | ||
this() { | ||
dcdProcess = new ExternalProcess(); | ||
} | ||
bool execute(char[][] arguments ,ref dstring output, dstring input) { | ||
ProtectedTextStorage stdoutTarget = new ProtectedTextStorage(); | ||
ExternalProcess dcdProcess = new ExternalProcess(); | ||
//TODO: Working Directory, where is that? | ||
//TODO: Inform user when dcd-client is not available. | ||
dcdProcess.run("dcd-client".dup, arguments, "/usr/bin".dup, stdoutTarget); | ||
dcdProcess.write(input); | ||
|
||
while(dcdProcess.poll() == ExternalProcessState.Running){ } | ||
|
||
output = stdoutTarget.readText(); | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
module dlangide.tools.d.editorTool; | ||
|
||
import dlangide.tools.editorTool; | ||
import dlangide.tools.d.DCDInterface; | ||
import dlangide.ui.dsourceedit; | ||
import dlangui.widgets.editors; | ||
import dlangide.ui.frame; | ||
import std.stdio; | ||
import std.string; | ||
import dlangui.core.logger; | ||
|
||
import std.conv; | ||
|
||
class DEditorTool : EditorTool | ||
{ | ||
|
||
|
||
this(IDEFrame frame) { | ||
_dcd = new DCDInterface(); | ||
super(frame); | ||
} | ||
|
||
override bool goToDefinition(DSourceEdit editor, TextPosition caretPosition) { | ||
|
||
|
||
auto content = editor.text(); | ||
auto byteOffset = caretPositionToByteOffset(content, caretPosition); | ||
|
||
char[][] arguments = ["-l".dup, "-c".dup]; | ||
arguments ~= [to!(char[])(byteOffset)]; | ||
//arguments ~= [to!(char[])(editor.projectSourceFile.filename())]; | ||
|
||
dstring output; | ||
_dcd.execute(arguments, output, content); | ||
|
||
string[] outputLines = to!string(output).splitLines(); | ||
Log.d("DCD:", outputLines); | ||
|
||
foreach(string outputLine ; outputLines) { | ||
if(outputLine.indexOf("Not Found".dup) == -1) { | ||
auto split = outputLine.indexOf("\t"); | ||
if(split == -1) { | ||
Log.d("DCD output format error."); | ||
break; | ||
} | ||
if(indexOf(outputLine[0 .. split],"stdin".dup) != -1) { | ||
Log.d("Declaration is in current file. Can jump to it."); | ||
auto target = to!int(outputLine[split+1 .. $]); | ||
auto destPos = byteOffsetToCaret(content, target); | ||
editor.setCaretPos(destPos.line,destPos.pos); | ||
} | ||
else { | ||
auto filename = outputLine[0 .. split]; | ||
if(_frame !is null) { | ||
_frame.openSourceFile(filename); | ||
auto target = to!int(outputLine[split+1 .. $]); | ||
auto destPos = byteOffsetToCaret(_frame.currentEditor.text(), target); | ||
|
||
_frame.currentEditor.setCaretPos(destPos.line,destPos.pos); | ||
} | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
override dstring[] getCompletions(DSourceEdit editor, TextPosition caretPosition) { | ||
auto content = editor.text(); | ||
auto byteOffset = caretPositionToByteOffset(content, caretPosition); | ||
|
||
char[][] arguments = ["-c".dup]; | ||
arguments ~= [to!(char[])(byteOffset)]; | ||
//arguments ~= [to!(char[])(editor.projectSourceFile.filename())]; | ||
|
||
dstring output; | ||
_dcd.execute(arguments, output, content); | ||
|
||
char[] state = "".dup; | ||
dstring[] suggestions; | ||
foreach(dstring outputLine ; output.splitLines()) { | ||
if(outputLine == "identifiers") { | ||
state = "identifiers".dup; | ||
} | ||
else if(outputLine == "calltips") { | ||
state = "calltips".dup; | ||
} | ||
else { | ||
auto split = outputLine.indexOf("\t"); | ||
if(split < 0) { | ||
break; | ||
} | ||
if(state == "identifiers") { | ||
suggestions ~= outputLine[0 .. split]; | ||
} | ||
} | ||
} | ||
return suggestions; | ||
} | ||
|
||
|
||
private: | ||
DCDInterface _dcd; | ||
|
||
int caretPositionToByteOffset(dstring content, TextPosition caretPosition) { | ||
auto line = 0; | ||
auto pos = 0; | ||
auto bytes = 0; | ||
foreach(c; content) { | ||
bytes++; | ||
if(c == '\n') { | ||
line++; | ||
} | ||
if(line == caretPosition.line) { | ||
if(pos == caretPosition.pos) | ||
break; | ||
pos++; | ||
} | ||
} | ||
return bytes; | ||
} | ||
|
||
TextPosition byteOffsetToCaret(dstring content, int byteOffset) { | ||
int bytes = 0; | ||
int line = 0; | ||
int pos = 0; | ||
TextPosition textPos; | ||
foreach(c; content) { | ||
if(bytes == byteOffset) { | ||
//We all good. | ||
textPos.line = line; | ||
textPos.pos = pos; | ||
return textPos; | ||
} | ||
bytes++; | ||
if(c == '\n') | ||
{ | ||
line++; | ||
pos = 0; | ||
} | ||
else { | ||
pos++; | ||
} | ||
} | ||
return textPos; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This caused a compiler issue for me at the last return in the function: "Statement is not reachable".