-
Notifications
You must be signed in to change notification settings - Fork 36
Add Code complete #62
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -248,12 +248,21 @@ __get_cxx_version () | |||||
return kernel_res; | ||||||
} | ||||||
|
||||||
nl::json interpreter::complete_request_impl(const std::string& /*code*/, int cursor_pos) | ||||||
nl::json interpreter::complete_request_impl(const std::string& code, int cursor_pos) | ||||||
{ | ||||||
return xeus::create_complete_reply( | ||||||
nl::json::array(), /*matches*/ | ||||||
cursor_pos, /*cursor_start*/ | ||||||
cursor_pos /*cursor_end*/ | ||||||
std::vector<std::string> results; | ||||||
|
||||||
// split the input to have only the word in the back of the cursor | ||||||
std::string delims = " \t\n`!@#$^&*()=+[{]}\\|;:\'\",<>?."; | ||||||
std::size_t _cursor_pos = cursor_pos; | ||||||
auto text = split_line(code, delims, _cursor_pos); | ||||||
std::string to_complete = text.back().c_str(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: redundant call to 'c_str' [readability-redundant-string-cstr]
Suggested change
|
||||||
|
||||||
Cpp::CodeComplete(results, code.c_str(), 1, _cursor_pos + 1); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no member named 'CodeComplete' in namespace 'Cpp' [clang-diagnostic-error] Cpp::CodeComplete(results, code.c_str(), 1, _cursor_pos + 1);
^ |
||||||
|
||||||
return xeus::create_complete_reply(results /*matches*/, | ||||||
cursor_pos - to_complete.length() /*cursor_start*/, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'unsigned long' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions] cursor_pos - to_complete.length() /*cursor_start*/,
^ |
||||||
cursor_pos /*cursor_end*/ | ||||||
); | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,10 @@ | |
#include "xparser.hpp" | ||
|
||
#include <cstddef> | ||
#include <regex> | ||
#include <sstream> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace xcpp | ||
{ | ||
|
@@ -26,4 +29,29 @@ namespace xcpp | |
std::size_t last = str.find_last_not_of(' '); | ||
return str.substr(first, last - first + 1); | ||
} | ||
|
||
std::vector<std::string> | ||
split_line(const std::string& input, const std::string& delims, std::size_t cursor_pos) | ||
{ | ||
// passing -1 as the submatch index parameter performs splitting | ||
std::vector<std::string> result; | ||
std::stringstream ss; | ||
|
||
ss << "["; | ||
for (auto c : delims) | ||
{ | ||
ss << "\\" << c; | ||
} | ||
ss << "]"; | ||
|
||
std::regex re(ss.str()); | ||
|
||
std::copy( | ||
std::sregex_token_iterator(input.begin(), input.begin() + cursor_pos + 1, re, -1), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: narrowing conversion from 'std::size_t' (aka 'unsigned long') to signed type '__gnu_cxx::__normal_iterator<const char *, std::basic_string>::difference_type' (aka 'long') is implementation-defined [cppcoreguidelines-narrowing-conversions] std::sregex_token_iterator(input.begin(), input.begin() + cursor_pos + 1, re, -1),
^ |
||
std::sregex_token_iterator(), | ||
std::back_inserter(result) | ||
); | ||
|
||
return result; | ||
} | ||
} |
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.
warning: invalid case style for variable '_cursor_pos' [readability-identifier-naming]
src/xinterpreter.cpp:260: