Skip to content

Commit

Permalink
Merge pull request #8 from PlugFox/feature/actions
Browse files Browse the repository at this point in the history
Dart-Code.dart-code & Dart-Code.flutter dependencies
  • Loading branch information
PlugFox authored Aug 23, 2024
2 parents 17b8e3c + 3116a33 commit 5441345
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 24 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/checkout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
os:
- ubuntu-latest
#- macos-latest
#- windows-latest
runs-on: ${{ matrix.os }}
defaults:
run:
Expand Down
66 changes: 55 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@
"engines": {
"vscode": "^1.92.0"
},
"extensionKind": [
"workspace"
],
"capabilities": {
"virtualWorkspaces": {
"supported": "limited",
"description": "Some functionality may be limited for remote files in virtual workspaces."
},
"untrustedWorkspaces": {
"supported": false
}
},
"license": "SEE LICENSE IN LICENSE",
"publisher": "plugfox",
"bugs": {
"url": "https://github.com/PlugFox/flutter-plus/issues",
Expand All @@ -23,39 +36,66 @@
"Programming Languages"
],
"keywords": [
"dart",
"flutter",
"snippets",
"fox"
"Programming Languages",
"Snippets",
"Linters",
"Formatters",
"Debuggers",
"Dart",
"Flutter",
"Actions",
"Shortcuts"
],
"activationEvents": [
"onCommand:extension.sealed-states",
"workspaceContains:**/pubspec.yaml"
"onLanguage:dart",
"workspaceContains:pubspec.yaml",
"workspaceContains:*/pubspec.yaml",
"workspaceContains:*/*/pubspec.yaml",
"workspaceContains:*.dart",
"workspaceContains:*/*.dart",
"workspaceContains:*/*/*.dart",
"onCommand:flutter.createProject",
"onCommand:dart.createProject",
"onUri"
],
"main": "./dist/extension.js",
"contributes": {
"commands": [
{
"command": "flutter-plus.sealed-states",
"title": "Create Sealed States"
"title": "Create Sealed States",
"category": "Flutter Plus"
},
{
"command": "flutter-plus.wrap-sizedbox",
"title": "Wrap with SizedBox"
"title": "Wrap with SizedBox",
"category": "Flutter Plus"
},
{
"command": "flutter-plus.wrap-listenablebuilder",
"title": "Wrap with ListenableBuilder"
"title": "Wrap with ListenableBuilder",
"category": "Flutter Plus"
},
{
"command": "flutter-plus.wrap-valuelistenablebuilder",
"title": "Wrap with ValueListenableBuilder<T>"
"title": "Wrap with ValueListenableBuilder<T>",
"category": "Flutter Plus"
},
{
"command": "flutter-plus.wrap-repaintboundary",
"title": "Wrap with RepaintBoundary"
"title": "Wrap with RepaintBoundary",
"category": "Flutter Plus"
}
],
"views": {
"flutter": [
{
"id": "flutter-plus.sidebar-actions",
"name": "Actions",
"when": "dart-code:anyFlutterProjectLoaded"
}
]
},
"submenus": [
{
"id": "flutter-plus.submenu",
Expand Down Expand Up @@ -94,6 +134,10 @@
}
]
},
"extensionDependencies": [
"Dart-Code.dart-code",
"Dart-Code.flutter"
],
"scripts": {
"compile": "npm run check-types && npm run lint && node esbuild.js",
"watch": "npm-run-all -p watch:*",
Expand Down
2 changes: 2 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const dartCodeExtensionIdentifier = "Dart-Code.dart-code";
export const flutterExtensionIdentifier = "Dart-Code.flutter";
85 changes: 73 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import * as vscode from 'vscode';

import {
commands,
languages
} from "vscode";

import {
sealedStates,
wrapWithListenableBuilder,
Expand All @@ -17,22 +12,88 @@ import {
CodeActionWrap,
} from './code-actions';


import {
dartCodeExtensionIdentifier,
flutterExtensionIdentifier,
} from "./constants";

/* import fs from 'fs';
import path from 'path'; */

import {
SdkCommands,
} from './utils';

const DART_MODE = { language: "dart", scheme: "file" };

export function activate(context: vscode.ExtensionContext) {
export async function activate(context: vscode.ExtensionContext): Promise<void> {
// Ensure we have a Dart extension.
const dartExt = vscode.extensions.getExtension(dartCodeExtensionIdentifier);
if (!dartExt) {
// This should not happen since the Flutter extension has a dependency on the Dart one
// but just in case, we'd like to give a useful error message.
throw new Error("The Dart extension is not installed, Flutter extension is unable to activate.");
}
await dartExt.activate();
if (!dartExt.exports) {
console.error("The Dart extension did not provide an exported API. Maybe it failed to activate or is not the latest version?");
return;
}

// Ensure we have a Flutter extension.
const flutterExt = vscode.extensions.getExtension(flutterExtensionIdentifier);
if (!flutterExt) {
// This should not happen since the Flutter extension has a dependency on the Dart one
// but just in case, we'd like to give a useful error message.
throw new Error("The Flutter extension is not installed, Flutter Plus extension is unable to activate.");
}
await flutterExt.activate();

// Register SDK commands.
const sdkCommands = new SdkCommands(context, dartExt.exports);

//console.log('Congratulations, your extension "flutter-plus" is now active!');

registerCommands(context);
//registerActionButtons(context);
registerWrappers(context);
}

/// Register all commands.
function registerCommands(context: vscode.ExtensionContext) {
context.subscriptions.push(
/* vscode.commands.registerCommand('flutter-plus.helloWorld', () => {
vscode.window.showInformationMessage('Hello World from Flutter Plus!');
}), */
commands.registerCommand("flutter-plus.sealed-states", sealedStates),
commands.registerCommand("flutter-plus.wrap-sizedbox", wrapWithSizedBox),
commands.registerCommand("flutter-plus.wrap-listenablebuilder", wrapWithListenableBuilder),
commands.registerCommand("flutter-plus.wrap-valuelistenablebuilder", wrapWithValueListenableBuilder),
commands.registerCommand("flutter-plus.wrap-repaintboundary", wrapWithRepaintBoundary),
vscode.commands.registerCommand("flutter-plus.sealed-states", sealedStates),
);
}

languages.registerCodeActionsProvider(
/* function registerActionButtons(context: vscode.ExtensionContext) {
function runPubGet() {
// Example of running `dart pub get` or `flutter pub get`
const pubspecPath = path.join(vscode.workspace.workspaceFolders?.[0]?.uri.fsPath || '', 'pubspec.yaml');
if (fs.existsSync(pubspecPath)) {
const pubspecContent = fs.readFileSync(pubspecPath, 'utf8');
const isFlutterApp = pubspecContent.includes('flutter:');
const command = isFlutterApp ? 'flutter pub get' : 'dart pub get';
executeCommand(command);
}
}
context.subscriptions.push(vscode.commands.registerCommand('flutter-plus.pub-get', () => {
runPubGet();
}));
} */

/// Register all wrappers (Wrap With...).
function registerWrappers(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.commands.registerCommand("flutter-plus.wrap-sizedbox", wrapWithSizedBox),
vscode.commands.registerCommand("flutter-plus.wrap-listenablebuilder", wrapWithListenableBuilder),
vscode.commands.registerCommand("flutter-plus.wrap-valuelistenablebuilder", wrapWithValueListenableBuilder),
vscode.commands.registerCommand("flutter-plus.wrap-repaintboundary", wrapWithRepaintBoundary),
vscode.languages.registerCodeActionsProvider(
DART_MODE,
new CodeActionWrap(),
),
Expand Down
8 changes: 8 additions & 0 deletions src/utils/execute-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as vscode from 'vscode';

// Execute a command in the terminal
export function executeCommand(command: string) {
const terminal = vscode.window.createTerminal('Flutter Plus');
terminal.sendText(command);
terminal.show();
}
3 changes: 3 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export * from "./execute-command";
export * from "./get-selected-text";
export * from "./sdk";
export * from "./wrap-with";

23 changes: 23 additions & 0 deletions src/utils/sdk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as vscode from "vscode";

export class SdkCommands {
// TODO: Find an easy way to share the API signature class.
constructor(context: vscode.ExtensionContext, private dartExtensionApi: any) {

// context.subscriptions.push(vs.commands.registerCommand("flutter.createSampleProject",
// (_) => this.runFunctionIfSupported(dartExtensionApi.flutterCreateSampleProject)));
}

private async runFunctionIfSupported<T>(f: () => Promise<T>): Promise<T | undefined> {
if (!f) {
this.showApiMismatchError();
return undefined;
}

return f();
}

private showApiMismatchError(): void {
vscode.window.showErrorMessage("The installed version of the Dart extension does not support this feature.");
}
}

0 comments on commit 5441345

Please sign in to comment.