-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Environment vars and empty daml.yamls in multi-ide #20306
base: main-2.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import * as fs from "fs"; | |
import { ViewColumn, ExtensionContext } from "vscode"; | ||
import * as util from "util"; | ||
import fetch from "node-fetch"; | ||
import { DamlLanguageClient } from "./language_client"; | ||
import { DamlLanguageClient, EnvVars } from "./language_client"; | ||
import { resetTelemetryConsent, getTelemetryConsent } from "./telemetry"; | ||
import { WebviewFiles, getVRFilePath } from "./virtual_resource_manager"; | ||
import * as child_process from "child_process"; | ||
|
@@ -79,7 +79,7 @@ export async function activate(context: vscode.ExtensionContext) { | |
// Try to find a client for the virtual resource- if we can't, log to DevTools | ||
let foundAClient = false; | ||
for (let projectPath in damlLanguageClients) { | ||
if (vrPath.startsWith(projectPath)) { | ||
if (isPrefixOfVrPath(projectPath)) { | ||
foundAClient = true; | ||
damlLanguageClients[projectPath].virtualResourceManager.createOrShow( | ||
title, | ||
|
@@ -148,7 +148,7 @@ export async function activate(context: vscode.ExtensionContext) { | |
} | ||
|
||
interface IdeManifest { | ||
[multiPackagePath: string]: { [envVarName: string]: string }; | ||
[multiPackagePath: string]: EnvVars; | ||
} | ||
|
||
function parseIdeManifest(path: string): IdeManifest | null { | ||
|
@@ -221,7 +221,7 @@ async function startLanguageServers(context: ExtensionContext) { | |
(await fileExists(rootPath + "/.envrc")) && | ||
vscode.extensions.getExtension("mkhl.direnv") == null; | ||
|
||
if (envrcExistsWithoutExt && gradleSupport) { | ||
if (envrcExistsWithoutExt) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. People use |
||
const warningMessage = | ||
"Found an .envrc file but the recommended direnv VSCode extension was not installed. Daml IDE may fail to start due to missing environment." + | ||
"\nWould you like to install this extension or attempt to continue without it?"; | ||
|
@@ -285,7 +285,7 @@ async function startLanguageServers(context: ExtensionContext) { | |
} else { | ||
const languageClient = await DamlLanguageClient.build( | ||
rootPath, | ||
{}, | ||
process.env, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is why env vars broke |
||
config, | ||
consent, | ||
context, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,10 +32,13 @@ import Data.Foldable (traverse_) | |
import Data.List (find, isInfixOf, isSuffixOf) | ||
import qualified Data.Map as Map | ||
import Data.Maybe (fromMaybe, mapMaybe) | ||
import qualified Data.Set as Set | ||
import qualified Data.Text.IO as T | ||
import qualified Language.LSP.Types as LSP | ||
import qualified Language.LSP.Types.Lens as LSP | ||
import System.Exit (exitSuccess) | ||
import System.FilePath.Posix (takeDirectory, takeExtension, takeFileName) | ||
import System.FilePath ((</>)) | ||
|
||
parseCustomResult :: Aeson.FromJSON a => String -> Either LSP.ResponseError Aeson.Value -> Either LSP.ResponseError a | ||
parseCustomResult name = | ||
|
@@ -146,26 +149,31 @@ subIdeMessageHandler miState unblock ide bs = do | |
logDebug miState $ "Backwarding response to " <> show method <> ":\n" <> show msg | ||
sendClient miState msg | ||
|
||
-- Returns whether the message should be forwarded to IDE (We do not want to forward open/close messages on a daml.yaml) | ||
handleOpenFilesNotification | ||
:: forall (m :: LSP.Method 'LSP.FromClient 'LSP.Notification) | ||
. MultiIdeState | ||
-> LSP.NotificationMessage m | ||
-> FilePath | ||
-> IO () | ||
-> IO Bool | ||
handleOpenFilesNotification miState mess path = atomically $ case (mess ^. LSP.method, takeFileName path) of | ||
(LSP.STextDocumentDidOpen, name) | ".daml" `isSuffixOf` name -> do | ||
home <- getSourceFileHome miState path | ||
addOpenFile miState home $ DamlFile path | ||
pure True | ||
(LSP.STextDocumentDidClose, name) | ".daml" `isSuffixOf` name -> do | ||
home <- getSourceFileHome miState path | ||
removeOpenFile miState home $ DamlFile path | ||
-- Also remove from the source mapping, in case project structure changes while we're not tracking the file | ||
sourceFileHomeHandleDamlFileDeleted miState path | ||
(LSP.STextDocumentDidOpen, "daml.yaml") -> | ||
setDamlYamlOpen miState (PackageHome $ takeDirectory path) True | ||
(LSP.STextDocumentDidClose, "daml.yaml") -> | ||
setDamlYamlOpen miState (PackageHome $ takeDirectory path) False | ||
_ -> pure () | ||
pure True | ||
(LSP.STextDocumentDidOpen, "daml.yaml") -> do | ||
setDamlYamlOpen miState True $ PackageHome $ takeDirectory path | ||
pure False | ||
(LSP.STextDocumentDidClose, "daml.yaml") -> do | ||
setDamlYamlOpen miState False $ PackageHome $ takeDirectory path | ||
pure False | ||
_ -> pure True | ||
|
||
clientMessageHandler :: MultiIdeState -> IO () -> B.ByteString -> IO () | ||
clientMessageHandler miState unblock bs = do | ||
|
@@ -254,10 +262,27 @@ clientMessageHandler miState unblock bs = do | |
LSP.FcDeleted -> do | ||
shutdownIdeByHome miState home | ||
handleRemovedPackageOpenFiles miState home | ||
atomically $ onSubIde_ miState home $ \ideData -> ideData {ideDataIsFullDamlYaml = False} | ||
LSP.FcCreated -> do | ||
handleCreatedPackageOpenFiles miState home | ||
rebootIdeByHome miState home | ||
LSP.FcChanged -> rebootIdeByHome miState home | ||
isFullDamlYaml <- shouldHandleDamlYamlChange <$> T.readFile (unPackageHome home </> "daml.yaml") | ||
if isFullDamlYaml | ||
then do | ||
handleCreatedPackageOpenFiles miState home | ||
rebootIdeByHome miState home | ||
else shutdownIdeByHome miState home | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a daml.yaml containing only an sdk version is created, we shutdown its IDE and don't update any state |
||
atomically $ onSubIde_ miState home $ \ideData -> ideData {ideDataIsFullDamlYaml = isFullDamlYaml} | ||
LSP.FcChanged -> do | ||
isFullDamlYaml <- shouldHandleDamlYamlChange <$> T.readFile (unPackageHome home </> "daml.yaml") | ||
oldIdeData <- atomically $ onSubIde miState home $ \ideData -> (ideData {ideDataIsFullDamlYaml = isFullDamlYaml}, ideData) | ||
if isFullDamlYaml | ||
then do | ||
when (not (ideDataIsFullDamlYaml oldIdeData) && Set.null (ideDataOpenFiles oldIdeData)) $ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to treat a daml.yaml file going from "only sdk-version" to a full package as though the daml.yaml was created. |
||
handleCreatedPackageOpenFiles miState home | ||
rebootIdeByHome miState home | ||
else do | ||
when (not $ Set.null $ ideDataOpenFiles oldIdeData) $ handleRemovedPackageOpenFiles miState home | ||
sendClient miState $ clearDiagnostics $ unPackageHome home </> "daml.yaml" | ||
shutdownIdeByHome miState home | ||
void $ updatePackageData miState | ||
|
||
"multi-package.yaml" -> do | ||
|
@@ -308,9 +333,9 @@ clientMessageHandler miState unblock bs = do | |
|
||
ForwardNotification mess (Single path) -> do | ||
logDebug miState $ "single not on method " <> show meth <> " over path " <> path | ||
handleOpenFilesNotification miState mess path | ||
shouldForward <- handleOpenFilesNotification miState mess path | ||
-- Notifications aren't stored, so failure to send can be ignored | ||
sendSubIdeByPath miState path (castFromClientMessage msg) | ||
when shouldForward $ sendSubIdeByPath miState path (castFromClientMessage msg) | ||
|
||
ForwardNotification _ AllNotification -> do | ||
logDebug miState $ "all not on method " <> show meth | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small fix missing from this pr