diff --git a/GOnpp/AutoCompletion/AutoCompletion.cpp b/GOnpp/AutoCompletion/AutoCompletion.cpp index d49cc3d..8c4f2a6 100644 --- a/GOnpp/AutoCompletion/AutoCompletion.cpp +++ b/GOnpp/AutoCompletion/AutoCompletion.cpp @@ -9,6 +9,7 @@ #include "CmdDlg.h" #include "StringUtils/tokens.h" #include "StringUtils/WcharMbcsConverter.h" +#include "StringUtils/tstring.h" #ifdef max #undef max @@ -180,16 +181,6 @@ bool AutoCompletion::show_calltip() { _npp.send_scintilla(SCI_CALLTIPCANCEL); - // Invented algorithm: - // - walk back, until an outstanding open parenthesis '(' is found - // - TODO: parse and skip strings - // - TODO: walk more than one line, but invent some reasonable stop-condition (open curly bracket '{', or close bracket on column 0?) - // - walk over the parenthesis too, find preceding word - // - if not a word precedes, cancel - // - then, if not column 0, run gocode - // - keep only the 'func' results, and only the (first) one matching the word preceding the paren - // - show calltip - LRESULT pos = _npp.send_scintilla(SCI_GETCURRENTPOS); std::vector buf(std::min(pos, 1024)); @@ -197,70 +188,28 @@ bool AutoCompletion::show_calltip() return true; } - // retrieve some chunk of text preceding the cursor - Sci_TextRange range; - range.chrg.cpMax = pos; - range.chrg.cpMin = pos - long(buf.size()-1); - range.lpstrText = &buf[0]; - _npp.send_scintilla(SCI_GETTEXTRANGE, 0, (LPARAM)&range); - - int paren_i = 0; - int parens = 0; - int i=buf.size()-2; - for (; i>=0; i--) { - // first, try to find unmatched open paren '(' - // FIXME: don't get confused with strings, chars, comments... - // TODO: to simplify, stop on first newline? - if (parens >= 0) { - switch (buf[i]) { - case ')': - parens++; - break; - case '(': - parens--; - paren_i = i; - break; - } - continue; - } - - if (!is_go_word_char(buf[i])) { - continue; - } - - i++; - break; - } - if (i <= 0) { - return true; - } - // find completions of word preceding the dangling paren std::vector completions; - if (!run_gocode(pos-long(buf.size())+long(i+1), completions)) { + if (!run_gocode(pos, completions)) { return false; } - // find the word preceding the dangling paren - int j = i-1; - while (j>=0 && is_go_word_char(buf[j])) { - j--; - } - std::vector word_buf = WcharMbcsConverter::char2tchar( - std::string(buf.begin()+j+1, buf.begin()+i).c_str()); - tstring word(&word_buf[0]); - //_cmdDlg.setText(word); - //_cmdDlg.appendText(_T("*\n")); - ////_cmdDlg.setText(_T("[")+word+_T("]\n\n")); - //_cmdDlg.setText(_T("calltips\n")); + tstring suggestions; for (std::vector::iterator c=completions.begin(); c!=completions.end(); ++c) { - //_cmdDlg.appendText(c->type + _T(",,") + c->name + _T(",,") + c->signature); - if (c->signature.substr(0, 4) == _T("func") && c->name == word) { - std::vector sig = WcharMbcsConverter::tchar2char(c->signature.c_str() + 4); - _npp.send_scintilla(SCI_CALLTIPSHOW, pos-long(buf.size())+long(paren_i+1), (LPARAM)&sig[0]); - return true; + if (c->type != _T("func")) { + continue; + } + _cmdDlg.appendText(c->type + _T(",,") + c->name + _T(",,") + c->signature); + if (0name + _T(" - ") + c->signature; + } + + if (0 sig = WcharMbcsConverter::tchar2char(suggestions.c_str()); + _npp.send_scintilla(SCI_CALLTIPSHOW, pos, (LPARAM)&sig[0]); } if (completions.empty()) { diff --git a/GOnpp/PluginDefinition.cpp b/GOnpp/PluginDefinition.cpp index a8512db..288810f 100755 --- a/GOnpp/PluginDefinition.cpp +++ b/GOnpp/PluginDefinition.cpp @@ -76,21 +76,9 @@ bool initialize_go_cmd(){ free(raw_goroot); return false; } - - // if GOBIN is set set assume that go.exe is there - DWORD length = ::GetEnvironmentVariable(_T("GOBIN"), raw_goroot, MAX_ENVIRON); - if (length != 0){ - if (::PathCombine(GO_CMD_tmp, raw_goroot, _T("go.exe")) == NULL) { - return false; - } - ::PathQuoteSpaces(GO_CMD_tmp); - GO_CMD = tstring(GO_CMD_tmp); - free(raw_goroot); - return true; - } - + // if GOROOT is set assume that go.exe is there - length = ::GetEnvironmentVariable(_T("GOROOT"), raw_goroot, MAX_ENVIRON); + DWORD length = ::GetEnvironmentVariable(_T("GOROOT"), raw_goroot, MAX_ENVIRON); if (length != 0){ if (::PathCombine(GO_CMD_tmp, raw_goroot, _T("bin\\go.exe")) == NULL) { return false; diff --git a/GOnpp/plugins/GOnpp.dll b/GOnpp/plugins/GOnpp.dll new file mode 100644 index 0000000..94f5340 Binary files /dev/null and b/GOnpp/plugins/GOnpp.dll differ