ecode: Implemented LSP textDocument/references ("Find References to Symbol Under Cursor").

This commit is contained in:
Martín Lucas Golini
2023-02-05 03:26:13 -03:00
parent 3aaf5dc48a
commit ecba3fa9aa
14 changed files with 250 additions and 87 deletions

View File

@@ -29,8 +29,8 @@ static String textLine( const std::string& fileText, const size_t& fromPos, size
nlStartPtr++;
while ( ++endPtr && *endPtr != '\0' && *endPtr != '\n' ) {
}
relCol = String::utf8Length(
fileText.substr( nlStartPtr - stringStartPtr, startPtr - nlStartPtr ) );
relCol =
String::utf8Length( fileText.substr( nlStartPtr - stringStartPtr, startPtr - nlStartPtr ) );
// if the line to substract is massive we only get the fist kilobyte of that line, since the
// line is only shared for visual aid.
return fileText.substr( nlStartPtr - stringStartPtr,
@@ -65,12 +65,11 @@ searchInFileHorspool( const std::string& file, const std::string& text, const bo
totNl += countNewLines( fileText, lSearchRes, searchRes );
String str(
textLine( caseSensitive ? fileText : fileTextOriginal, searchRes, relCol ) );
res.push_back(
{ str,
{ { (Int64)totNl, (Int64)relCol },
{ (Int64)totNl, (Int64)( relCol + String::utf8Length( text ) ) } },
searchRes,
static_cast<Int64>( searchRes + text.size() ) } );
res.push_back( { str,
{ { (Int64)totNl, (Int64)relCol },
{ (Int64)totNl, (Int64)( relCol + String::utf8Length( text ) ) } },
searchRes,
static_cast<Int64>( searchRes + text.size() ) } );
lSearchRes = searchRes;
searchRes += text.size();
}
@@ -185,4 +184,12 @@ void ProjectSearch::find( const std::vector<std::string> files, std::string stri
}
}
void ProjectSearch::ResultModel::removeLastNewLineCharacter() {
for ( auto& r : mResult ) {
for ( auto& r2 : r.results )
if ( !r2.line.empty() && r2.line.back() == '\n' )
r2.line.pop_back();
}
}
} // namespace ecode