Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Add workspaceContains and onView to extension activationEvents in package.json #42

Closed
1 task done
RandomFractals opened this issue May 31, 2023 · 4 comments
Closed
1 task done
Labels
enhancement New feature or request

Comments

@RandomFractals
Copy link
Contributor

RandomFractals commented May 31, 2023

Workspace Contains activation event docs:

https://code.visualstudio.com/api/references/activation-events#workspaceContains

Originally posted by @RandomFractals in #25 (comment)

@RandomFractals RandomFractals added the enhancement New feature or request label May 31, 2023
@RandomFractals
Copy link
Contributor Author

RandomFractals commented Jun 1, 2023

After reading workspaceContains activation even docs, we now know why our .evidence glob pattern did not work. That activation kicks in only when the folder is open:

This activation event is emitted and interested extensions will be activated whenever a folder is opened and the folder contains at least one file that matches a glob pattern.

"activationEvents": [
    "workspaceContains:**/.editorconfig"
]

So, I think we'll just check for **/package.json to activate extension.

After activation we can check if that config has evidence dependencies and exit gracefully, if it's just another web app project.

@RandomFractals
Copy link
Contributor Author

We can also use onView activation event and check if the built-in simpler browser we are using is open, which happens when you close vscode after viewing evidence app page. Simple browser uses simpleBrowser.view id.

Docs: https://code.visualstudio.com/api/references/activation-events#onView

RandomFractals added a commit that referenced this issue Jun 1, 2023
@RandomFractals RandomFractals changed the title Add workspaceContains to extension activationEvents in package.json Add workspaceContains and onView to extension activationEvents in package.json Jun 1, 2023
@RandomFractals
Copy link
Contributor Author

Reopening Evidence project with an active Simple Browser view should now enable Evidence start and other custom commands:

image

@RandomFractals
Copy link
Contributor Author

RandomFractals commented Jun 1, 2023

The other checks we already perform in Evidence ext. activation code and in #43

  // check for evidence app files and node modules
  const packageJson = await loadPackageJson();
  const evidenceFiles = await workspace.findFiles('**/.evidence/**/*.*');
  if (workspace.workspaceFolders && evidenceFiles.length > 0 &&
    hasDependency(packageJson, '@evidence-dev/evidence')) {
    updateProjectContext();

    // check for node modules
    const nodeModules = await workspace.findFiles('**/node_modules/**/*.*');
    if (nodeModules.length > 0) {
      // show start dev server status
      statusBar.showStart();
    }
    else {
      // show install node modules status
      statusBar.showInstall();
    }
  }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant