Skip to content

Commit

Permalink
fix NPE in CProjectChangeMonitor (#52) (#53)
Browse files Browse the repository at this point in the history
fixes #52
  • Loading branch information
ghentschke committed May 9, 2023
1 parent e7686a1 commit b0d5da6
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,22 @@ public void handleEvent(CProjectDescriptionEvent event) {
if (project != null && LspEditorPreferencesTester.preferLspEditor(project)) {
ICConfigurationDescription newConfig = newCProjectDecription.getDefaultSettingConfiguration();
var cwdBuilder = newConfig.getBuildSetting().getBuilderCWD();
try {
var cwdString = CCorePlugin.getDefault().getCdtVariableManager().resolveValue(cwdBuilder.toOSString(), "", null, newConfig);
var projectLocation = project.getLocation().addTrailingSeparator().toOSString();
var databasePath = cwdString.replace(projectLocation, "");
if (cwdBuilder != null) {
try {
ClangdConfigurationManager.setCompilationDatabase(project, databasePath);
} catch (ScannerException e) {
var status = new Status(IStatus.ERROR, LspEditorUiPlugin.PLUGIN_ID, e.getMessage());
var configFile = ClangdConfigurationManager.CLANGD_CONFIG_FILE_NAME;
LspUtils.showErrorMessage(LspEditorUiMessages.CProjectChangeMonitor_yaml_scanner_error,
LspEditorUiMessages.CProjectChangeMonitor_yaml_scanner_error_message + projectLocation + configFile , status);
var cwdString = CCorePlugin.getDefault().getCdtVariableManager().resolveValue(cwdBuilder.toOSString(), "", null, newConfig);
var projectLocation = project.getLocation().addTrailingSeparator().toOSString();
var databasePath = cwdString.replace(projectLocation, "");
try {
ClangdConfigurationManager.setCompilationDatabase(project, databasePath);
} catch (ScannerException e) {
var status = new Status(IStatus.ERROR, LspEditorUiPlugin.PLUGIN_ID, e.getMessage());
var configFile = ClangdConfigurationManager.CLANGD_CONFIG_FILE_NAME;
LspUtils.showErrorMessage(LspEditorUiMessages.CProjectChangeMonitor_yaml_scanner_error,
LspEditorUiMessages.CProjectChangeMonitor_yaml_scanner_error_message + projectLocation + configFile , status);
}
} catch (CoreException | IOException e) {
LspEditorUiPlugin.logError(e.getMessage(), e);
}
} catch (CoreException | IOException e) {
LspEditorUiPlugin.logError(e.getMessage(), e);
}
}
}
Expand Down

0 comments on commit b0d5da6

Please sign in to comment.