Commit 703d29a3 authored by Enrique Alcántara's avatar Enrique Alcántara 3️⃣
Browse files

fix: Fix Language Server web views in Remote dev environments

parent 3de30f2f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ module.exports = {
    onDidChangeTelemetryEnabled: jest.fn(),
    openExternal: jest.fn(),
    appName: 'test-app-name',
    asExternalUri: jest.fn(),
  },
  CommentMode: { Editing: 0, Preview: 1 },
  StatusBarAlignment: { Left: 0 },
+2 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ describe('LSDuoChatWebviewController', () => {
  beforeEach(() => {
    // mocking for isUrlAvailable
    global.fetch = jest.fn().mockImplementation(() => Promise.resolve({ ok: true }));
    jest.mocked(vscode.env.asExternalUri).mockResolvedValue(vscode.Uri.parse(mockUrl.toString()));
    controller = new LSDuoChatWebviewController({
      viewId: mockViewId,
      url: mockUrl,
@@ -60,12 +61,11 @@ describe('LSDuoChatWebviewController', () => {

    const resolveWebviewPromise = controller.resolveWebviewView(mockWebviewView);
    await jest.runAllTicks();

    if (setChatReady) {
      controller.setChatReady();
    }

    jest.advanceTimersByTime(advanceTimersBy);
    await jest.advanceTimersByTimeAsync(advanceTimersBy);
    await resolveWebviewPromise;

    return resolveWebviewPromise;
+7 −3
Original line number Diff line number Diff line
import * as vscode from 'vscode';
import { IS_OSX } from '../constants';
import { escapeHtml } from './escape_html';
import html from './templates/webview.template.html';
import osxKeyboardEventScript from './templates/osx_keyboard_event_fix.template.html';

export const getWebviewContent = (url: URL, title: string) => {
export const getWebviewContent = async (url: URL, title: string) => {
  const externalUri = await vscode.env.asExternalUri(vscode.Uri.parse(url.toString()));
  const externalUrl = new URL(externalUri.toString());

  const safeTitle = escapeHtml(title);
  const safeOrigin = escapeHtml(url.origin);
  const safeUrl = encodeURI(url.toString());
  const safeOrigin = escapeHtml(externalUrl.origin);
  const safeUrl = encodeURI(externalUrl.toString());

  let webviewHtml = html
    .replace(/{{origin}}/g, safeOrigin)
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ describe('KnowledgeGraphWebview', () => {
    } as unknown as vscode.WebviewPanel;

    jest.mocked(vscode.window.createWebviewPanel).mockReturnValue(panel);
    jest.mocked(getWebviewContent).mockReturnValue('<html>Mock Content</html>');
    jest.mocked(getWebviewContent).mockResolvedValue('<html>Mock Content</html>');
    jest.mocked(vscode.commands.executeCommand).mockResolvedValue(undefined);
    jest.mocked(vscode.commands.registerCommand).mockReturnValue({
      dispose: jest.fn(),
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ export class KnowledgeGraphWebview implements vscode.Disposable {
          },
        );

        panel.webview.html = getWebviewContent(knowledgeGraphUrl, 'Knowledge Graph');
        panel.webview.html = await getWebviewContent(knowledgeGraphUrl, 'Knowledge Graph');

        panel.onDidDispose(() => {
          panel = undefined;
Loading