| 1 |
#include "PHPExpression.h" |
| 2 |
#include "PHPLookupTable.h" |
| 3 |
#include "PHPSourceFile.h" |
| 4 |
#include "csCodeCompletePhpHandler.h" |
| 5 |
#include "csManager.h" |
| 6 |
|
| 7 |
csCodeCompletePhpHandler::csCodeCompletePhpHandler(csManager* manager) |
| 8 |
: csCommandHandlerBase(manager) |
| 9 |
{ |
| 10 |
} |
| 11 |
|
| 12 |
csCodeCompletePhpHandler::~csCodeCompletePhpHandler() {} |
| 13 |
|
| 14 |
void csCodeCompletePhpHandler::DoProcessCommand(const JSONItem& options) |
| 15 |
{ |
| 16 |
CHECK_STR_PARAM("path", m_path); |
| 17 |
CHECK_STR_PARAM_OPTIONAL("unsaved-buffer-path", m_unsavedBufferPath); |
| 18 |
CHECK_INT_PARAM("position", m_position); |
| 19 |
CHECK_STR_PARAM("symbols-path", m_symbolsPath); |
| 20 |
|
| 21 |
// Guess the symbols db path |
| 22 |
PHPLookupTable lookup; |
| 23 |
if(wxFileName::DirExists(m_symbolsPath)) { |
| 24 |
// the provided path is the folder, build the symbols path |
| 25 |
m_symbolsPath << wxFileName::GetPathSeparator() << ".codelite" << wxFileName::GetPathSeparator() |
| 26 |
<< "phpsymbols.db"; |
| 27 |
} |
| 28 |
clDEBUG() << "Using symbols db:" << m_symbolsPath; |
| 29 |
lookup.Open(wxFileName(m_symbolsPath)); |
| 30 |
if(!lookup.IsOpened()) { |
| 31 |
return; |
| 32 |
} |
| 33 |
|
| 34 |
PHPSourceFile sourceFile(wxFileName(m_unsavedBufferPath.IsEmpty() ? m_path : m_unsavedBufferPath), &lookup); |
| 35 |
sourceFile.SetFilename(m_path); // update the file name to the real path |
| 36 |
sourceFile.SetParseFunctionBody(true); |
| 37 |
sourceFile.Parse(); |
| 38 |
lookup.UpdateSourceFile(sourceFile); |
| 39 |
|
| 40 |
PHPExpression::Ptr_t expr(new PHPExpression(sourceFile.GetText().Mid(0, m_position))); |
| 41 |
PHPEntityBase::Ptr_t resolved = expr->Resolve(lookup, m_path); |
| 42 |
if(resolved) { |
| 43 |
PHPEntityBase::List_t matches = lookup.FindChildren( |
| 44 |
resolved->GetDbId(), PHPLookupTable::kLookupFlags_StartsWith | expr->GetLookupFlags(), expr->GetFilter()); |
| 45 |
JSON root(cJSON_Array); |
| 46 |
JSONItem arr = root.toElement(); |
| 47 |
std::for_each(matches.begin(), matches.end(), [&](PHPEntityBase::Ptr_t e) { arr.arrayAppend(e->ToJSON()); }); |
| 48 |
char* result = arr.FormatRawString(m_manager->GetConfig().IsPrettyJSON()); |
| 49 |
std::cout << result << std::endl; |
| 50 |
free(result); |
| 51 |
|
| 52 |
} else { |
| 53 |
std::cout << "[]" << std::endl; |
| 54 |
} |
| 55 |
} |