diff --git a/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QEclipseEditorUtils.java b/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QEclipseEditorUtils.java index 266c8fa4..d4c3e00f 100644 --- a/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QEclipseEditorUtils.java +++ b/plugin/src/software/aws/toolkits/eclipse/amazonq/util/QEclipseEditorUtils.java @@ -106,7 +106,7 @@ public static boolean shouldIndentVertically(final StyledText textWidget, final public static Optional getOpenFileUri() { try { return getOpenFilePath() - .map(filePath -> Paths.get(filePath).toUri().toString()); + .map(filePath -> Paths.get(filePath).toUri().toString()); } catch (Exception e) { Activator.getLogger().error("Unexpected error when determining open file path", e); return Optional.empty(); @@ -146,7 +146,11 @@ private static String getOpenFilePath(final IEditorInput editorInput) { // rather than the workspace location, so we need to reference the cached file path return AbapUtil.getSemanticCachePath(file.getFullPath().toOSString()); } - return file.getRawLocation().toOSString(); + // Fallback to semantic cache location if rawLocation is null, one of the use + // cases is also file when users connect to a remote SAP project + return (file.getRawLocation() != null) + ? file.getRawLocation().toOSString() + : AbapUtil.getSemanticCachePath(file.getFullPath().toOSString()); } else { throw new AmazonQPluginException("Unexpected editor input type: " + editorInput.getClass().getName()); } @@ -172,7 +176,8 @@ public static Optional getSelectionRange(final ITextEditor editor) { var end = new Position(endLine, endColumn); return Optional.of(new Range(start, end)); } catch (org.eclipse.jface.text.BadLocationException e) { - Activator.getLogger().error("Error occurred while attempting to determine selected text position in editor", e); + Activator.getLogger() + .error("Error occurred while attempting to determine selected text position in editor", e); } } return Optional.empty(); @@ -184,7 +189,8 @@ public static Optional getActiveSelectionRange() { } /* - * Inserts the given text at cursor position and returns cursor position range of the text + * Inserts the given text at cursor position and returns cursor position range + * of the text */ public static Optional insertAtCursor(final String text) { var editor = getActiveTextEditor(); @@ -254,8 +260,9 @@ private static String applyIndentation(final String text, final String indentati StringBuilder indentedText = new StringBuilder(lines.get(0)); for (int i = 1; i < lines.size(); i++) { indentedText.append("\n") - .append(lines.get(i).isEmpty() ? "" : indentation) // Don't apply the gap to empty lines (eg: end of string may end in a newline) - .append(lines.get(i)); + .append(lines.get(i).isEmpty() ? "" : indentation) // Don't apply the gap to empty lines (eg: end of + // string may end in a newline) + .append(lines.get(i)); } return indentedText.toString(); @@ -268,7 +275,8 @@ private static String getIndentation(final IDocument document, final int offset) var content = document.get(lineOffset, offset - lineOffset); if (content.trim().isEmpty()) { - // if current line is blank or contains only whitespace, return line as indentation + // if current line is blank or contains only whitespace, return line as + // indentation return content; } return content.substring(0, content.indexOf(content.trim())); @@ -319,14 +327,18 @@ public static IExecutionListener getAutoTriggerExecutionListener(final Consumer< public void notHandled(final String commandId, final NotHandledException exception) { return; } + @Override - public void postExecuteFailure(final String commandId, final org.eclipse.core.commands.ExecutionException exception) { + public void postExecuteFailure(final String commandId, + final org.eclipse.core.commands.ExecutionException exception) { return; } + @Override public void postExecuteSuccess(final String commandId, final Object returnValue) { return; } + @Override public void preExecute(final String commandId, final ExecutionEvent event) { callback.accept(commandId); @@ -348,17 +360,18 @@ public static IQInlineTypeaheadProcessor getAutoCloseSettings(final ITextEditor return new GenericTypeheadProcessor(); } switch (contentTypeName) { - // TODO: Add more supported file types here: - case "Java Source File": - IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode("org.eclipse.jdt.ui"); - boolean isBracesSetToAutoClose = preferences.getBoolean("closeBraces", true); - boolean isBracketsSetToAutoClose = preferences.getBoolean("closeBrackets", true); - boolean isStringSetToAutoClose = preferences.getBoolean("closeStrings", true); - return new JavaTypeaheadProcessor(editor, isBracesSetToAutoClose, isBracketsSetToAutoClose, isStringSetToAutoClose); - case "JavaScript Source File": - return new JavascriptTypeaheadProcessor(); - default: - return new GenericTypeheadProcessor(); + // TODO: Add more supported file types here: + case "Java Source File": + IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode("org.eclipse.jdt.ui"); + boolean isBracesSetToAutoClose = preferences.getBoolean("closeBraces", true); + boolean isBracketsSetToAutoClose = preferences.getBoolean("closeBrackets", true); + boolean isStringSetToAutoClose = preferences.getBoolean("closeStrings", true); + return new JavaTypeaheadProcessor(editor, isBracesSetToAutoClose, isBracketsSetToAutoClose, + isStringSetToAutoClose); + case "JavaScript Source File": + return new JavascriptTypeaheadProcessor(); + default: + return new GenericTypeheadProcessor(); } }