Skip to content

Commit

Permalink
Revert "Update VS Code and enable Intellisense" (#6228)
Browse files Browse the repository at this point in the history
Reverts #6222
  • Loading branch information
Rheeseyb authored Aug 13, 2024
1 parent 9e27de3 commit 58bb813
Show file tree
Hide file tree
Showing 34 changed files with 3,354 additions and 2,225 deletions.
6 changes: 3 additions & 3 deletions editor/src/components/code-editor/code-editor-container.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React from 'react'
import { Substores, useEditorState } from '../editor/store/store-hook'
import { MONACO_EDITOR_IFRAME_BASE_URL } from '../../common/env-vars'
import { createIframeUrl } from '../../core/shared/utils'
import { getUnderlyingVSCodeBridgeID } from '../editor/store/editor-state'
import { VSCodeLoadingScreen } from './vscode-editor-loading-screen'
import { setBranchNameFromURL } from '../../utils/branches'
import { getEditorBranchNameFromURL, setBranchNameFromURL } from '../../utils/branches'
import { VSCODE_EDITOR_IFRAME_ID } from '../../core/vscode/vscode-bridge'

const VSCodeIframeContainer = React.memo((props: { vsCodeSessionID: string }) => {
const vsCodeSessionID = props.vsCodeSessionID
const baseIframeSrc = createIframeUrl(window.location.origin, 'vscode-editor-iframe/')
const baseIframeSrc = createIframeUrl(MONACO_EDITOR_IFRAME_BASE_URL, 'vscode-editor-iframe/')
const url = new URL(baseIframeSrc)
url.searchParams.append('vs_code_session_id', vsCodeSessionID)
url.searchParams.append('vscode-coi', '') // Required to enable intellisense

setBranchNameFromURL(url.searchParams)

Expand Down
14 changes: 9 additions & 5 deletions editor/src/components/editor/store/vscode-changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import {
import type {
UpdateDecorationsMessage,
SelectedElementChanged,
FromUtopiaToVSCodeMessage,
AccumulatedToVSCodeMessage,
ToVSCodeMessageNoAccumulated,
} from 'utopia-vscode-common'
import { accumulatedToVSCodeMessage, toVSCodeExtensionMessage } from 'utopia-vscode-common'
import type { EditorState } from './editor-state'
import { getHighlightBoundsForElementPaths } from './editor-state'
import { shallowEqual } from '../../../core/shared/equality-utils'
Expand Down Expand Up @@ -300,15 +302,15 @@ export const emptyProjectChanges: ProjectChanges = {
selectedChanged: null,
}

function projectChangesToVSCodeMessages(local: ProjectChanges): Array<FromUtopiaToVSCodeMessage> {
let messages: Array<FromUtopiaToVSCodeMessage> = []
export function projectChangesToVSCodeMessages(local: ProjectChanges): AccumulatedToVSCodeMessage {
let messages: Array<ToVSCodeMessageNoAccumulated> = []
if (local.updateDecorations != null) {
messages.push(local.updateDecorations)
}
if (local.selectedChanged != null) {
messages.push(local.selectedChanged)
}
return messages
return accumulatedToVSCodeMessage(messages)
}

export function getProjectChanges(
Expand All @@ -332,5 +334,7 @@ export function getProjectChanges(
export function sendVSCodeChanges(changes: ProjectChanges) {
applyProjectChanges(changes.fileChanges.changesForVSCode)
const toVSCodeAccumulated = projectChangesToVSCodeMessages(changes)
toVSCodeAccumulated.forEach((message) => sendMessage(message))
if (toVSCodeAccumulated.messages.length > 0) {
sendMessage(toVSCodeExtensionMessage(toVSCodeAccumulated))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
selectedElementChangedMessageFromHighlightBounds,
sendMessage,
} from '../../../core/vscode/vscode-bridge'
import { toVSCodeExtensionMessage } from 'utopia-vscode-common'
import { isRegulaNavigatorRow, type NavigatorRow } from '../navigator-row'
import { useDispatch } from '../../editor/store/dispatch-context'
import { isRight } from '../../../core/shared/either'
Expand Down Expand Up @@ -99,7 +100,9 @@ export function useGetNavigatorClickActions(
// when we click on an already selected item we should force vscode to navigate there
if (selected && highlightBounds != null) {
sendMessage(
selectedElementChangedMessageFromHighlightBounds(highlightBounds, 'force-navigation'),
toVSCodeExtensionMessage(
selectedElementChangedMessageFromHighlightBounds(highlightBounds, 'force-navigation'),
),
)
}
return actionsForSingleSelection(targetPath, row, conditionalOverrideUpdate)
Expand Down
50 changes: 31 additions & 19 deletions editor/src/core/vscode/vscode-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ import {
deletePathChange,
ensureDirectoryExistsChange,
initProject,
isClearLoadingScreen,
isEditorCursorPositionChanged,
isFromVSCodeExtensionMessage,
isIndexedDBFailure,
isMessageListenersReady,
isUtopiaVSCodeConfigValues,
isVSCodeBridgeReady,
isVSCodeFileChange,
isVSCodeFileDelete,
isVSCodeReady,
openFileMessage,
projectDirectory,
projectTextFile,
selectedElementChanged,
setFollowSelectionConfig,
setVSCodeTheme,
toVSCodeExtensionMessage,
updateDecorationsMessage,
writeProjectFileChange,
} from 'utopia-vscode-common'
Expand Down Expand Up @@ -132,16 +131,27 @@ export function initVSCodeBridge(
// Store the source
vscodeIFrame = messageEvent.source
dispatch([markVSCodeBridgeReady(true)])
} else if (isEditorCursorPositionChanged(data)) {
dispatch([selectFromFileAndPosition(data.filePath, data.line, data.column)])
} else if (isUtopiaVSCodeConfigValues(data)) {
dispatch([updateConfigFromVSCode(data.config)])
} else if (isVSCodeReady(data)) {
dispatch([sendCodeEditorInitialisation()])
} else if (isClearLoadingScreen(data)) {
if (!loadingScreenHidden) {
loadingScreenHidden = true
dispatch([hideVSCodeLoadingScreen()])
} else if (isFromVSCodeExtensionMessage(data)) {
const message = data.message
switch (message.type) {
case 'EDITOR_CURSOR_POSITION_CHANGED':
dispatch([selectFromFileAndPosition(message.filePath, message.line, message.column)])
break
case 'UTOPIA_VSCODE_CONFIG_VALUES':
dispatch([updateConfigFromVSCode(message.config)])
break
case 'VSCODE_READY':
dispatch([sendCodeEditorInitialisation()])
break
case 'CLEAR_LOADING_SCREEN':
if (!loadingScreenHidden) {
loadingScreenHidden = true
dispatch([hideVSCodeLoadingScreen()])
}
break
default:
const _exhaustiveCheck: never = message
throw new Error(`Unhandled message type${JSON.stringify(message)}`)
}
} else if (isVSCodeFileChange(data)) {
const { filePath, fileContent } = data
Expand All @@ -159,6 +169,8 @@ export function initVSCodeBridge(
dispatch(actionsToDispatch)
} else if (isVSCodeFileDelete(data)) {
dispatch([deleteFileFromVSCode(data.filePath)])
} else if (isIndexedDBFailure(data)) {
dispatch([setIndexedDBFailed(true)])
}
}

Expand All @@ -170,11 +182,11 @@ export function sendMessage(message: FromUtopiaToVSCodeMessage) {
}

export function sendOpenFileMessage(filePath: string, bounds: Bounds | null) {
sendMessage(openFileMessage(filePath, bounds))
sendMessage(toVSCodeExtensionMessage(openFileMessage(filePath, bounds)))
}

export function sendSetFollowSelectionEnabledMessage(enabled: boolean) {
sendMessage(setFollowSelectionConfig(enabled))
sendMessage(toVSCodeExtensionMessage(setFollowSelectionConfig(enabled)))
}

export function applyProjectChanges(changes: Array<ProjectFileChange>) {
Expand Down Expand Up @@ -231,7 +243,7 @@ export function getCodeEditorDecorations(editorState: EditorState): UpdateDecora

export function sendCodeEditorDecorations(editorState: EditorState) {
const decorationsMessage = getCodeEditorDecorations(editorState)
sendMessage(decorationsMessage)
sendMessage(toVSCodeExtensionMessage(decorationsMessage))
}

export function getSelectedElementChangedMessage(
Expand Down Expand Up @@ -272,7 +284,7 @@ export function sendSelectedElement(newEditorState: EditorState) {
'do-not-force-navigation',
)
if (selectedElementChangedMessage != null) {
sendMessage(selectedElementChangedMessage)
sendMessage(toVSCodeExtensionMessage(selectedElementChangedMessage))
}
}

Expand All @@ -290,5 +302,5 @@ function vsCodeThemeForTheme(theme: Theme): string {

export function sendSetVSCodeTheme(theme: Theme) {
const vsCodeTheme = vsCodeThemeForTheme(theme)
sendMessage(setVSCodeTheme(vsCodeTheme))
sendMessage(toVSCodeExtensionMessage(setVSCodeTheme(vsCodeTheme)))
}
8 changes: 4 additions & 4 deletions editor/src/templates/vscode-editor-iframe/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<meta id="vscode-workbench-builtin-extensions" data-settings="[]" />

<link
data-name="vs/workbench/workbench.web.main"
data-name="vs/workbench/workbench.web.api"
rel="stylesheet"
href="<%- UTOPIA_DOMAIN %>/vscode/vscode/vs/workbench/workbench.web.main.css?hash=<%- UTOPIA_SHA %>"
href="<%- UTOPIA_DOMAIN %>/vscode/vscode/vs/workbench/workbench.web.api.css?hash=<%- UTOPIA_SHA %>"
/>
<script src="<%- UTOPIA_DOMAIN %>/vscode/extensions.js?hash=<%- UTOPIA_SHA %>"></script>
</head>
Expand All @@ -36,8 +36,8 @@
</script>
<script src="<%- UTOPIA_DOMAIN %>/vscode/vscode/vs/loader.js?hash=<%- UTOPIA_SHA %>"></script>

<script src="<%- UTOPIA_DOMAIN %>/vscode/vscode/vs/workbench/workbench.web.main.nls.js?hash=<%- UTOPIA_SHA %>"></script>
<script src="<%- UTOPIA_DOMAIN %>/vscode/vscode/vs/workbench/workbench.web.main.js?hash=<%- UTOPIA_SHA %>"></script>
<script src="<%- UTOPIA_DOMAIN %>/vscode/vscode/vs/workbench/workbench.web.api.nls.js?hash=<%- UTOPIA_SHA %>"></script>
<script src="<%- UTOPIA_DOMAIN %>/vscode/vscode/vs/workbench/workbench.web.api.js?hash=<%- UTOPIA_SHA %>"></script>
<script src="<%- UTOPIA_DOMAIN %>/vscode/vscode/vs/code/browser/workbench/workbench.js?hash=<%- UTOPIA_SHA %>"></script>
<link rel="stylesheet" href="<%- UTOPIA_DOMAIN %>/editor/css/vscode-overrides.css" />
</html>
6 changes: 3 additions & 3 deletions release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ let
}) { inherit config; };

recentPkgs = import (builtins.fetchTarball {
name = "nixos-24.05";
url = https://github.com/NixOS/nixpkgs/archive/24.05.tar.gz;
name = "nixos-23.11";
url = https://github.com/NixOS/nixpkgs/archive/23.11.tar.gz;
# Hash obtained using `nix-prefetch-url --unpack <url>`
sha256 = "1lr1h35prqkd1mkmzriwlpvxcb34kmhc9dnr48gkm8hh089hifmx";
sha256 = "1ndiv385w1qyb3b18vw13991fzb9wg4cl21wglk89grsfsnra41k";
}) { inherit config; };

in
Expand Down
39 changes: 12 additions & 27 deletions server/src/Utopia/Web/Endpoints.hs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ injectIntoPage toInject@(_, _, _, _, editorScriptTags) (TagComment "editorScript
injectIntoPage toInject (firstTag : remainder) = firstTag : injectIntoPage toInject remainder
injectIntoPage _ [] = []

renderPageWithMetadata :: Maybe ProjectIdWithSuffix -> Maybe ProjectMetadata -> Maybe DB.DecodedProject -> Maybe Text -> Text -> ServerMonad ProjectPageResponse
renderPageWithMetadata :: Maybe ProjectIdWithSuffix -> Maybe ProjectMetadata -> Maybe DB.DecodedProject -> Maybe Text -> Text -> ServerMonad H.Html
renderPageWithMetadata possibleProjectID possibleMetadata possibleProject branchName pagePath = do
indexHtml <- getEditorTextContent branchName pagePath
siteRoot <- getSiteRoot
Expand All @@ -294,38 +294,38 @@ renderPageWithMetadata possibleProjectID possibleMetadata possibleProject branch
let reversedEditorScriptTags = partitionOutScriptDefer False $ reverse parsedTags
let editorScriptPreloads = preloadsForScripts $ reverse reversedEditorScriptTags
let updatedContent = injectIntoPage (ogTags, projectIDScriptTags, dependenciesTags, vscodePreloadTags, editorScriptPreloads) parsedTags
return $ addHeader "cross-origin" $ addHeader "same-origin" $ addHeader "credentialless" $ H.preEscapedToHtml $ renderTags updatedContent
return $ H.preEscapedToHtml $ renderTags updatedContent

innerProjectPage :: Maybe ProjectIdWithSuffix -> ProjectDetails -> Maybe DB.DecodedProject -> Maybe Text -> ServerMonad ProjectPageResponse
innerProjectPage :: Maybe ProjectIdWithSuffix -> ProjectDetails -> Maybe DB.DecodedProject -> Maybe Text -> ServerMonad H.Html
innerProjectPage (Just _) UnknownProject _ branchName = do
projectNotFoundHtml <- getEditorTextContent branchName "project-not-found/index.html"
return $ addHeader "cross-origin" $ addHeader "same-origin" $ addHeader "credentialless" $ H.preEscapedToHtml projectNotFoundHtml
return $ H.preEscapedToHtml projectNotFoundHtml
innerProjectPage possibleProjectID details possibleProject branchName =
renderPageWithMetadata possibleProjectID (projectDetailsToPossibleMetadata details) possibleProject branchName "index.html"

projectPage :: ProjectIdWithSuffix -> Maybe Text -> ServerMonad ProjectPageResponse
projectPage :: ProjectIdWithSuffix -> Maybe Text -> ServerMonad H.Html
projectPage projectIDWithSuffix@(ProjectIdWithSuffix projectID _) branchName = do
possibleMetadata <- getProjectMetadata projectID
possibleProject <- loadProject projectID
innerProjectPage (Just projectIDWithSuffix) possibleMetadata possibleProject branchName

emptyProjectPage :: Maybe Text -> ServerMonad ProjectPageResponse
emptyProjectPage :: Maybe Text -> ServerMonad H.Html
emptyProjectPage = innerProjectPage Nothing UnknownProject Nothing

innerPreviewPage :: Maybe ProjectIdWithSuffix -> ProjectDetails -> Maybe DB.DecodedProject -> Maybe Text -> ServerMonad ProjectPageResponse
innerPreviewPage :: Maybe ProjectIdWithSuffix -> ProjectDetails -> Maybe DB.DecodedProject -> Maybe Text -> ServerMonad H.Html
innerPreviewPage (Just _) UnknownProject _ branchName = do
projectNotFoundHtml <- getEditorTextContent branchName "project-not-found/index.html"
return $ addHeader "cross-origin" $ addHeader "same-origin" $ addHeader "credentialless" $ H.preEscapedToHtml projectNotFoundHtml
return $ H.preEscapedToHtml projectNotFoundHtml
innerPreviewPage possibleProjectID details possibleProject branchName =
renderPageWithMetadata possibleProjectID (projectDetailsToPossibleMetadata details) possibleProject branchName "preview/index.html"

previewPage :: ProjectIdWithSuffix -> Maybe Text -> ServerMonad ProjectPageResponse
previewPage :: ProjectIdWithSuffix -> Maybe Text -> ServerMonad H.Html
previewPage projectIDWithSuffix@(ProjectIdWithSuffix projectID _) branchName = do
possibleMetadata <- getProjectMetadata projectID
possibleProject <- loadProject projectID
innerPreviewPage (Just projectIDWithSuffix) possibleMetadata possibleProject branchName

emptyPreviewPage :: Maybe Text -> ServerMonad ProjectPageResponse
emptyPreviewPage :: Maybe Text -> ServerMonad H.Html
emptyPreviewPage = innerPreviewPage Nothing UnknownProject Nothing

getUserEndpoint :: Maybe Text -> ServerMonad UserResponse
Expand Down Expand Up @@ -529,27 +529,12 @@ addCacheControl = addMiddlewareHeader "Cache-Control" "public, immutable, max-ag
addCacheControlRevalidate :: Middleware
addCacheControlRevalidate = addMiddlewareHeader "Cache-Control" "public, must-revalidate, proxy-revalidate, max-age=0"

addCrossOriginResourcePolicy :: Middleware
addCrossOriginResourcePolicy = addMiddlewareHeader "Cross-Origin-Resource-Policy" "cross-origin"

addCrossOriginOpenerPolicy :: Middleware
addCrossOriginOpenerPolicy = addMiddlewareHeader "Cross-Origin-Opener-Policy" "same-origin"

addCrossOriginEmbedderPolicy :: Middleware
addCrossOriginEmbedderPolicy = addMiddlewareHeader "Cross-Origin-Embedder-Policy" "require-corp"

addCDNHeaders :: Middleware
addCDNHeaders = addCacheControl . addAccessControlAllowOrigin

addCDNHeadersCacheRevalidate :: Middleware
addCDNHeadersCacheRevalidate = addCacheControlRevalidate . addAccessControlAllowOrigin

addEditorAssetsHeaders :: Middleware
addEditorAssetsHeaders = addCDNHeaders . addCrossOriginResourcePolicy . addCrossOriginOpenerPolicy . addCrossOriginEmbedderPolicy

addVSCodeHeaders :: Middleware
addVSCodeHeaders = addCDNHeadersCacheRevalidate . addCrossOriginResourcePolicy . addCrossOriginOpenerPolicy . addCrossOriginEmbedderPolicy

fallbackOn404 :: Application -> Application -> Application
fallbackOn404 firstApplication secondApplication request sendResponse =
firstApplication request $ \firstAppResponse -> do
Expand All @@ -572,7 +557,7 @@ editorAssetsEndpoint notProxiedPath possibleBranchName = do
mainApp <- case possibleBranchName of
Just _ -> pure loadLocally
Nothing -> maybe (pure loadLocally) loadFromProxy possibleProxyManager
pure $ addEditorAssetsHeaders $ downloadWithFallbacks mainApp
pure $ addCDNHeaders $ downloadWithFallbacks mainApp

downloadGithubProjectEndpoint :: Maybe Text -> Text -> Text -> ServerMonad BL.ByteString
downloadGithubProjectEndpoint cookie owner repo = requireUser cookie $ \_ -> do
Expand All @@ -595,7 +580,7 @@ websiteAssetsEndpoint notProxiedPath = do
vsCodeAssetsEndpoint :: ServerMonad Application
vsCodeAssetsEndpoint = do
pathToServeFrom <- getVSCodeAssetRoot
addVSCodeHeaders <$> servePath pathToServeFrom Nothing
addCDNHeadersCacheRevalidate <$> servePath pathToServeFrom Nothing

wrappedWebAppLookup :: (Pieces -> IO LookupResult) -> Pieces -> IO LookupResult
wrappedWebAppLookup defaultLookup _ =
Expand Down
14 changes: 7 additions & 7 deletions server/src/Utopia/Web/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,15 @@ type LogoutAPI = "logout" :> Get '[HTML] (SetSessionCookies H.Html)

type GetUserAPI = "v1" :> "user" :> Get '[JSON] UserResponse

type ProjectPageResponse = Headers '[Header "Cross-Origin-Resource-Policy" Text, Header "Cross-Origin-Opener-Policy" Text, Header "Cross-Origin-Embedder-Policy" Text] (H.Html)
type EmptyProjectPageAPI = "p" :> BranchNameParam :> Get '[HTML] H.Html

type EmptyProjectPageAPI = "p" :> BranchNameParam :> Get '[HTML] ProjectPageResponse

type ProjectPageAPI = "p" :> Capture "project_id" ProjectIdWithSuffix :> BranchNameParam :> Get '[HTML] ProjectPageResponse
type ProjectPageAPI = "p" :> Capture "project_id" ProjectIdWithSuffix :> BranchNameParam :> Get '[HTML] H.Html

type LoadProjectFileAPI = "p" :> Capture "project_id" ProjectIdWithSuffix :> Header "If-None-Match" Text :> CaptureAll "file_path" Text :> RawM

type EmptyPreviewPageAPI = "share" :> BranchNameParam :> Get '[HTML] ProjectPageResponse
type EmptyPreviewPageAPI = "share" :> BranchNameParam :> Get '[HTML] H.Html

type PreviewPageAPI = "share" :> Capture "project_id" ProjectIdWithSuffix :> BranchNameParam :> Get '[HTML] ProjectPageResponse
type PreviewPageAPI = "share" :> Capture "project_id" ProjectIdWithSuffix :> BranchNameParam :> Get '[HTML] H.Html

type DownloadProjectResponse = Headers '[Header "Access-Control-Allow-Origin" Text] Value

Expand Down Expand Up @@ -263,4 +261,6 @@ packagerAPI = Proxy
packagerLink :: Text -> Text -> Text
packagerLink jsPackageName jsPackageVersion =
let versionedName = jsPackageName <> "@" <> jsPackageVersion
in toUrlPiece $ safeLink apiProxy packagerAPI versionedName
in toUrlPiece $ safeLink apiProxy packagerAPI versionedName


2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ let

pythonAndPackages = pkgs.python3.withPackages(ps: with ps; [ pyusb tkinter pkgconfig ]);

basePackages = [ node pkgs.libsecret pkgs.libkrb5 pythonAndPackages pkgs.pkg-config pkgs.tmux pkgs.git pkgs.wget ] ++ nodePackages ++ linuxOnlyPackages ++ macOSOnlyPackages;
basePackages = [ node pkgs.libsecret pythonAndPackages pkgs.pkg-config pkgs.tmux pkgs.git pkgs.wget ] ++ nodePackages ++ linuxOnlyPackages ++ macOSOnlyPackages;
withServerBasePackages = basePackages ++ (lib.optionals includeServerBuildSupport baseServerPackages);
withServerRunPackages = withServerBasePackages ++ (lib.optionals includeRunLocallySupport serverRunPackages);
withReleasePackages = withServerRunPackages ++ (lib.optionals includeReleaseSupport releasePackages);
Expand Down
Loading

0 comments on commit 58bb813

Please sign in to comment.