Skip to content
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

wrong suggestions were given, remove algorithm that seeks for first pare... #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 15 additions & 66 deletions GOnpp/AutoCompletion/AutoCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "CmdDlg.h"
#include "StringUtils/tokens.h"
#include "StringUtils/WcharMbcsConverter.h"
#include "StringUtils/tstring.h"

#ifdef max
#undef max
Expand Down Expand Up @@ -180,87 +181,35 @@ 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<char> buf(std::min<long>(pos, 1024));
if (buf.size() == 0) {
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<completion> 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<TCHAR> 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<completion>::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<char> 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 (0<suggestions.length()) {
suggestions += _T("\r\n");
}
suggestions += c->name + _T(" - ") + c->signature;
}

if (0<suggestions.length()) {
std::vector<char> sig = WcharMbcsConverter::tchar2char(suggestions.c_str());
_npp.send_scintilla(SCI_CALLTIPSHOW, pos, (LPARAM)&sig[0]);
}

if (completions.empty()) {
Expand Down
16 changes: 2 additions & 14 deletions GOnpp/PluginDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Binary file added GOnpp/plugins/GOnpp.dll
Binary file not shown.