Skip to content

Commit

Permalink
Header file use context file's parser, if dont share parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
royqh1979 committed Dec 26, 2024
1 parent fedd877 commit 1dbf445
Showing 1 changed file with 41 additions and 21 deletions.
62 changes: 41 additions & 21 deletions RedPandaIDE/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3100,16 +3100,26 @@ void Editor::initParser()
if (pSettings->codeCompletion().shareParser()) {
mParser = sharedParser(calcParserLanguage());
} else {
mParser = std::make_shared<CppParser>();
mParser->setLanguage(calcParserLanguage());
mParser->setOnGetFileStream(
std::bind(
&EditorList::getContentFromOpenedEditor,pMainWindow->editorList(),
std::placeholders::_1, std::placeholders::_2));
resetCppParser(mParser);
mParser->setEnabled(
pSettings->codeCompletion().enabled() &&
(syntaxer()->language() == QSynedit::ProgrammingLanguage::CPP));
bool parserGot = false;
if (isC_CPPHeaderFile(mFileType) && !mContextFile.isEmpty()) {
Editor * e = pMainWindow->editorList()->getOpenedEditorByFilename(mContextFile);
if (e) {
mParser = e->parser();
parserGot=true;
}
}
if (!parserGot) {
mParser = std::make_shared<CppParser>();
mParser->setLanguage(calcParserLanguage());
mParser->setOnGetFileStream(
std::bind(
&EditorList::getContentFromOpenedEditor,pMainWindow->editorList(),
std::placeholders::_1, std::placeholders::_2));
resetCppParser(mParser);
mParser->setEnabled(
pSettings->codeCompletion().enabled() &&
(syntaxer()->language() == QSynedit::ProgrammingLanguage::CPP));
}
}
} else {
mParser = nullptr;
Expand Down Expand Up @@ -4599,18 +4609,21 @@ void Editor::doSetFileType(FileType newFileType, bool force)

Editor* Editor::openFileInContext(const QString &filename)
{
Editor *e=pMainWindow->openFile(filename);
if (e) {
if (!isC_CPPHeaderFile(e->fileType())
&& !isC_CPPSourceFile(e->fileType()))
e->setFileType(FileType::CCppHeader);
if (isC_CPPHeaderFile(e->fileType())) {
if (isC_CPPSourceFile(mFileType)) {
e->setContextFile(mFilename);
} else if (isC_CPPHeaderFile(mFileType) && !mContextFile.isEmpty()) {
e->setContextFile(mContextFile);
}
FileType fileType = getFileType(filename);
QString contextFile;
if (!isC_CPPHeaderFile(fileType)
&& !isC_CPPSourceFile(fileType))
fileType = FileType::CCppHeader;
if (isC_CPPHeaderFile(fileType)) {
if (isC_CPPSourceFile(mFileType)) {
contextFile = mFilename;
} else if (isC_CPPHeaderFile(mFileType) && !mContextFile.isEmpty()) {
contextFile = mContextFile;
}
}

Editor *e=pMainWindow->openFile(filename, true, nullptr, fileType, contextFile);
if (e) {
if (e->isVisible())
pMainWindow->updateClassBrowserForEditor(e);
}
Expand Down Expand Up @@ -4639,6 +4652,13 @@ void Editor::setContextFile(const QString &newContextFile)
if (isC_CPPHeaderFile(mFileType)) {
doSetFileType(mFileType, true);
applyColorScheme(pSettings->editor().colorScheme());
if (pSettings->codeCompletion().enabled()
&& !pSettings->codeCompletion().shareParser()
&& !mContextFile.isEmpty()) {
Editor * e = pMainWindow->editorList()->getOpenedEditorByFilename(mContextFile);
if (e)
mParser = e->parser();
}
reparse(false);
}
}
Expand Down

0 comments on commit 1dbf445

Please sign in to comment.