Skip to content

Commit

Permalink
Merge branch 'main' into taldekar/RemovePrintStatements
Browse files Browse the repository at this point in the history
  • Loading branch information
taldekar authored Nov 21, 2024
2 parents eb9b2b6 + e413706 commit 0640dd8
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static Builder builder() {
}

@Override
public LspInstallResult getLspInstallation() {
public synchronized LspInstallResult getLspInstallation() {
if (installResult != null) {
return installResult;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public LspFetchResult fetch(final PluginPlatform platform, final PluginArchitect

// delete invalid local cache
ArtifactUtils.deleteDirectory(downloadDirectory);
emitGetServer(Result.FAILED, serverVersion, LanguageServerLocation.CACHE, null, start);

// if all lsp target contents are successfully downloaded from remote location,
// return the download location
Expand All @@ -118,6 +119,7 @@ public LspFetchResult fetch(final PluginPlatform platform, final PluginArchitect
Activator.getLogger().info(String.format(
"Unable to download Amazon Q language server version v%s. Attempting to fetch from fallback location",
serverVersion));
emitGetServer(Result.FAILED, serverVersion, LanguageServerLocation.REMOTE, null, start);

// use the most compatible fallback cached lsp version
var fallbackDir = getFallback(serverVersion, platform, architecture, destination);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import software.aws.toolkits.eclipse.amazonq.lsp.manager.fetcher.RecordLspSetupArgs;
import software.aws.toolkits.eclipse.amazonq.plugin.Activator;
import software.aws.toolkits.telemetry.LanguageserverTelemetry;
import software.aws.toolkits.telemetry.TelemetryDefinitions.LanguageServerLocation;
import software.aws.toolkits.telemetry.TelemetryDefinitions.LanguageServerSetupStage;
import software.aws.toolkits.telemetry.TelemetryDefinitions.Result;

Expand Down Expand Up @@ -36,14 +37,14 @@ public static void emitSetupGetManifest(final Result result, final RecordLspSetu

public static void emitSetupGetServer(final Result result, final RecordLspSetupArgs args) {
emitSetupMetric(result, args, LanguageServerSetupStage.GET_SERVER);
if (result == Result.FAILED) {
if (result == Result.FAILED && args.getLocation() == LanguageServerLocation.UNKNOWN) {
emitSetupAll(Result.FAILED, args);
}
}

public static void emitSetupValidate(final Result result, final RecordLspSetupArgs args) {
emitSetupMetric(result, args, LanguageServerSetupStage.VALIDATE);
if (result == Result.FAILED) {
if (result == Result.FAILED && args.getLocation() != LanguageServerLocation.OVERRIDE) {
emitSetupAll(Result.FAILED, args);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

package software.aws.toolkits.eclipse.amazonq.util;

import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.IPartService;
import org.eclipse.ui.IWindowListener;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
Expand Down Expand Up @@ -60,6 +62,29 @@ public void windowOpened(final IWorkbenchWindow window) {
PlatformUI.getWorkbench().addWindowListener(windowListener);
activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

// Similar to how part listener needs to tell its child listener (i.e. document
// listener), the part listener needs to actively be attached to the part that
// contains the editors.
// Without this, because the window listener is attached after the subscribed
// events has already happened, the part listener will not be attached unless
// you trigger one of the subscribed events
Display.getDefault().timerExec(1000, new Runnable() {
@Override
public void run() {
IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWindow == null) {
Display.getDefault().timerExec(1000, this);
return;
}
IPartService partService = activeWindow.getPartService();
if (partService == null) {
Display.getDefault().timerExec(1000, this);
return;
}
partService.addPartListener(partListener);
}
});

// Aside from adding the listeners to the window, we would also need to add the
// listener actively for the first time
// Because all of the subscribed events has already happened.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void render(final GC gc, final int currentCaretOffset) {
// educated guess:
int endPadding = gc.getAdvanceWidth(symbol) / 4;
y = (invocationLine + lineInSuggestion + 1) * lineHt - fontHt;
x = gc.textExtent(text).x + endPadding;
x = gc.textExtent(text).x;
if (lineInSuggestion == 0) {
x += widget.getLocationAtOffset(invocationOffset).x;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void render(final GC gc, final int currentCaretOffset) {
textToRender = text;
x = widget.getLeftMargin();
} else {
x = gc.textExtent(text.substring(0, idxInLine)).x + gc.textExtent(" ").x / 4;
x = gc.textExtent(text.substring(0, idxInLine)).x;
textToRender = text.substring(idxInLine);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.IPartService;
import org.eclipse.ui.IWindowListener;
Expand All @@ -22,6 +23,7 @@

public class AutoTriggerTopLevelListenerTest {
private static MockedStatic<PlatformUI> platformUIMockStatic;
private static MockedStatic<Display> displayMockStatic;
private static IWorkbench workbenchMock;
private static IWorkbenchWindow windowMock;
private static IAutoTriggerPartListener partListenerMock;
Expand All @@ -37,11 +39,19 @@ public static void setUp() {
when(windowMock.getPartService()).thenReturn(partServiceMock);
when(workbenchMock.getActiveWorkbenchWindow()).thenReturn(windowMock);
partListenerMock = mock(IAutoTriggerPartListener.class);
displayMockStatic = mockStatic(Display.class);
Display displayMock = mock(Display.class);
displayMockStatic.when(Display::getDefault).thenReturn(displayMock);
}

@AfterAll
public static void tearDown() {
platformUIMockStatic.close();
if (platformUIMockStatic != null) {
platformUIMockStatic.close();
}
if (displayMockStatic != null) {
displayMockStatic.close();
}
}

@SuppressWarnings({ "rawtypes", "unchecked" })
Expand Down
10 changes: 9 additions & 1 deletion plugin/webview/src/q-ui/components/ssoLoginForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
@change="handleRegionInput"
tabindex="0"
>
<option v-for="region in regions" :key="region.id" :value="region.id">
<option v-for="region in sortedRegions" :key="region.id" :value="region.id">
{{ `${region.name} (${region.id})` }}
</option>
</select>
Expand Down Expand Up @@ -74,6 +74,14 @@ export default defineComponent({
}
},
computed: {
sortedRegions() {
const usEast1 = this.regions.find(r => r.id === 'us-east-1');
const otherRegions = this.regions
.filter(r => r.id !== 'us-east-1')
.sort((a, b) => a.name.localeCompare(b.name));

return usEast1 ? [usEast1, ...otherRegions] : otherRegions;
},
regions(): Region[] {
return this.$store.state.ssoRegions
},
Expand Down

0 comments on commit 0640dd8

Please sign in to comment.