Skip to content
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

Add checking availability Execute ember-cli command #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@
{
"id": "els.fileUsages",
"name": "Ember File Usages",
"when": "emberFileUsagesEnabled"
"when": "vscode-ember-unstable.emberFileUsagesEnabled"
}
]
},
"commands": [
{
"command": "els.runInEmberCLI",
"title": "Ember: Execute ember-cli command"
"title": "Ember: Execute ember-cli command",
"enablement": "vscode-ember-unstable.emberFastCliAvailable"
}
],
"configuration": {
Expand Down
14 changes: 13 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import {
StatusBarAlignment,
Uri,
} from 'vscode';
import { isEmberCliProject, isGlimmerXProject } from './workspace-utils';
import {
isEmberCliProject,
isGlimmerXProject,
packageAvailable,
} from './workspace-utils';
import {
LanguageClient,
LanguageClientOptions,
Expand Down Expand Up @@ -294,4 +298,12 @@ export async function activate(context: ExtensionContext) {
);
});
}

const emberFastCliAvailable = await packageAvailable('ember-fast-cli');

commands.executeCommand(
'setContext',
'vscode-ember-unstable.emberFastCliAvailable',
emberFastCliAvailable
);
}
4 changes: 2 additions & 2 deletions src/usages-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class UsagesProvider implements vscode.TreeDataProvider<Dependency> {

vscode.commands.executeCommand(
'setContext',
'emberFileUsagesEnabled',
'vscode-ember-unstable.emberFileUsagesEnabled',
enabled
);

Expand All @@ -48,7 +48,7 @@ export class UsagesProvider implements vscode.TreeDataProvider<Dependency> {
} else {
vscode.commands.executeCommand(
'setContext',
'emberFileUsagesEnabled',
'vscode-ember-unstable.emberFileUsagesEnabled',
false
);
}
Expand Down
10 changes: 10 additions & 0 deletions src/workspace-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ export async function isEmberCliProject(): Promise<boolean> {

return emberCliBuildFile.length > 0;
}

export async function packageAvailable(packageName: string): Promise<boolean> {
const files = await workspace.findFiles(
`**/node_modules/${packageName}/package.json`,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be incorrect path in case of monorepos, pnpm & such.
Likely, we need to get information about available ember addons from project (from uELS)
https://github.com/lifeart/ember-language-server/blob/component-context-info-origin/src/project.ts#L40

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Roger that.

null,
1
);

return files.length > 0;
}