Changeset View
Changeset View
Standalone View
Standalone View
plugins/clazy/jobparameters.cpp
Show First 20 Lines • Show All 141 Lines • ▼ Show 20 Line(s) | |||||
142 | } | 142 | } | ||
143 | 143 | | |||
144 | JobParameters::JobParameters(KDevelop::IProject* project, const QString& checkPath) | 144 | JobParameters::JobParameters(KDevelop::IProject* project, const QString& checkPath) | ||
145 | : m_checkPath(checkPath) | 145 | : m_checkPath(checkPath) | ||
146 | { | 146 | { | ||
147 | Q_ASSERT(project); | 147 | Q_ASSERT(project); | ||
148 | 148 | | |||
149 | auto projectRootPath = project->path().toLocalFile(); | 149 | auto projectRootPath = project->path().toLocalFile(); | ||
150 | auto projectCanonicalRootPath = QFileInfo(projectRootPath).canonicalFilePath(); | ||||
150 | 151 | | |||
151 | auto buildPath = project->buildSystemManager()->buildDirectory(project->projectItem()); | 152 | auto buildPath = project->buildSystemManager()->buildDirectory(project->projectItem()); | ||
152 | m_projectBuildPath = buildPath.toLocalFile(); | 153 | m_projectBuildPath = buildPath.toLocalFile(); | ||
153 | 154 | | |||
154 | buildPath.addPath(QStringLiteral("compile_commands.json")); | 155 | buildPath.addPath(QStringLiteral("compile_commands.json")); | ||
155 | 156 | | |||
156 | auto commandsFilePath = buildPath.toLocalFile(); | 157 | auto commandsFilePath = buildPath.toLocalFile(); | ||
157 | if (!QFile::exists(commandsFilePath)) { | 158 | if (!QFile::exists(commandsFilePath)) { | ||
158 | m_error = i18n("Compile commands file '%1' does not exist.", commandsFilePath); | 159 | m_error = i18n("Compile commands file '%1' does not exist.", commandsFilePath); | ||
159 | return; | 160 | return; | ||
160 | } | 161 | } | ||
161 | 162 | | |||
163 | const auto pathInfo = QFileInfo(m_checkPath); | ||||
164 | const bool checkPathIsFile = pathInfo.isFile(); | ||||
165 | const auto canonicalPathToCheck = checkPathIsFile ? pathInfo.canonicalFilePath() : QStringLiteral(""); | ||||
kossebau: Why the `QStringLiteral("")` and not just a plain `QString()`? | |||||
166 | | ||||
162 | if (!m_checkPath.isEmpty()) { | 167 | if (!m_checkPath.isEmpty()) { | ||
163 | const auto allFiles = compileCommandsFiles(commandsFilePath, m_error); | 168 | const auto allFiles = compileCommandsFiles(commandsFilePath, m_error); | ||
164 | if (!m_error.isEmpty()) { | 169 | if (!m_error.isEmpty()) { | ||
165 | return; | 170 | return; | ||
166 | } | 171 | } | ||
167 | 172 | | |||
168 | if (m_checkPath == projectRootPath) { | 173 | if (canonicalPathToCheck == projectCanonicalRootPath) { | ||
you can remove the previous check, since the second necessarily has to include it mwolff: you can remove the previous check, since the second necessarily has to include it | |||||
rjvbb: I assume you meant the first component of the `||` expression? | |||||
169 | m_sources = allFiles; | 174 | m_sources = allFiles; | ||
170 | } else { | 175 | } else { | ||
171 | const bool checkPathIsFile = QFileInfo(m_checkPath).isFile(); | | |||
172 | for (auto& file : allFiles) { | 176 | for (auto& file : allFiles) { | ||
173 | if (checkPathIsFile) { | 177 | if (checkPathIsFile) { | ||
174 | if (file == m_checkPath) { | 178 | if (file == canonicalPathToCheck) { | ||
175 | m_sources.clear(); | 179 | m_sources.clear(); | ||
176 | m_sources += m_checkPath; | 180 | m_sources += canonicalPathToCheck; | ||
we don't do this anywhere else - I'd suggest you always operate on canonical paths note that you may want to pretty print paths before showing them to the user anyways. there's a function somewhere (Project?) that takes a path and turns it into a relative-to-project-root string ready for consumption by the user mwolff: we don't do this anywhere else - I'd suggest you always operate on canonical paths
note that… | |||||
Yes, that would be something like Core::self()->projectController()->prettyFileName(urlDoc->url(), KDevelop::IProjectController::FormatPlain); (took me way longer than reasonable to remember where I might find it being used ...) It seems though that this is already being done (ProblemModel::reset()), did I miss a place where that is not yet so? rjvbb: Yes, that would be something like
```
Core::self()->projectController()->prettyFileName(urlDoc… | |||||
177 | break; | 181 | break; | ||
178 | } | 182 | } | ||
179 | } else if (file.startsWith(m_checkPath)) { | 183 | } else if (file.startsWith(m_checkPath) || file.startsWith(canonicalPathToCheck)) { | ||
180 | m_sources += file; | 184 | m_sources += file; | ||
181 | } | 185 | } | ||
182 | } | 186 | } | ||
183 | } | 187 | } | ||
184 | } | 188 | } | ||
185 | 189 | | |||
186 | ProjectSettings projectSettings; | 190 | ProjectSettings projectSettings; | ||
187 | projectSettings.setSharedConfig(project->projectConfiguration()); | 191 | projectSettings.setSharedConfig(project->projectConfiguration()); | ||
▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines |
Why the QStringLiteral("") and not just a plain QString()?