Skip to content

Commit

Permalink
Implement basic features (#1)
Browse files Browse the repository at this point in the history
Features include:
 - Automatic PlatformIO Core installation
 - Project Initialization
 - C/C++ Autocomplete Index Rebuild
  • Loading branch information
dmytrokyrychuk authored and ivankravets committed May 25, 2017
1 parent 6de8076 commit 3e49514
Show file tree
Hide file tree
Showing 20 changed files with 1,435 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"plugins": [
"transform-class-properties"
],
"presets": [
["env", {
"targets": {
"node": "7.4"
}
}]
],
"sourceMap": "inline"
}
7 changes: 7 additions & 0 deletions .esformatter
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"root": true,

"indent": {
"value": " "
}
}
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
!.eslintrc.js
/node_modules/**
/lib/**
51 changes: 51 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module.exports = {
'env': {
'browser': false,
'es6': true,
'node': true,
'jasmine': true,
},
'extends': ['eslint:recommended'],
'parser': 'babel-eslint',
'parserOptions': {
'ecmaVersion': 6,
'sourceType': 'module',
},
'plugins': [
'sort-imports-es6-autofix',
],
'rules': {
'brace-style': ['error', '1tbs'],
'comma-dangle': ['error', {
'arrays': 'always-multiline',
'objects': 'always-multiline',
'functions': 'never',
}],
'curly': ['warn', 'all'],
'indent': [
'warn',
2,
{
'SwitchCase': 1,
},
],
'linebreak-style': ['error', 'unix'],
'no-console': [
'error',
{
'allow': ['log', 'error'],
},
],
'no-var': 'error',
'object-curly-spacing': ['warn', 'always'],
'prefer-const': 'error',
'quotes': ['error', 'single', 'avoid-escape'],
'semi': ['error', 'always'],
'sort-imports-es6-autofix/sort-imports-es6': [2, {
'ignoreCase': false,
'ignoreMemberSort': false,
'memberSyntaxSortOrder': ['none', 'all', 'multiple', 'single'],
}],
'space-infix-ops': 'warn',
},
};
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules/
/lib/
*.vsix
9 changes: 9 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.vscode/**
.vscode-test/**
src/**
test/**
.babelrc
.esformatter
.eslintignore
.eslintrc.js
.gitignore
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Change Log

All notable changes to the "platformio-ide" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [Unreleased]
- Initial release
79 changes: 79 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"name": "platformio-ide",
"displayName": "PlatformIO IDE",
"description": "Official PlatformIO IDE for Visual Studio Code. PlatformIO is an open source ecosystem for IoT development. Cross-platform build system and library manager. Contin",
"version": "0.0.1-beta.0",
"publisher": "platformio",
"license": "Apache-2.0",
"engines": {
"vscode": "^1.12.0"
},
"categories": [
"Other"
],
"activationEvents": [
"*"
],
"main": "./lib/index",
"contributes": {
"commands": [
{
"command": "platformio-ide.init-project",
"title": "PlatformIO: Initialize project"
},
{
"command": "platformio-ide.rebuild-index",
"title": "PlatformIO: Rebuild index"
}
],
"configuration": {
"type": "object",
"title": "PlatformIO IDE configuration",
"properties": {
"platformio-ide.useBuiltinPIOCore": {
"type": "boolean",
"default": true,
"description": "Use built-in PlatformIO Core"
},
"platformio-ide.useDevelopmentPIOCore": {
"type": "boolean",
"default": false,
"description": "Use development version of PlatformIO Core"
},
"platformio-ide.autoRebuildAutocompleteIndex": {
"type": "boolean",
"default": true,
"description": "Automatically rebuild C/C++ Project Index when platformio.ini is changed or when new libraries are installed."
}
}
}
},
"scripts": {
"lint": "eslint .eslintrc.js src",
"format": "esformatter -i .eslintrc.js 'src/**.js' && eslint --fix .eslintrc.js src",
"build": "babel src --out-dir lib && echo 'Done!'",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "node ./node_modules/vscode/bin/test",
"vscode:prepublish": "npm run build"
},
"devDependencies": {
"@types/node": "^7.0.21",
"babel-cli": "^6.24.1",
"babel-eslint": "^7.2.3",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-env": "^1.5.1",
"esformatter": "^0.10.0",
"eslint": "^3.19.0",
"eslint-plugin-sort-imports-es6-autofix": "^0.1.1",
"vscode": "^1.0.0"
},
"dependencies": {
"cross-spawn": "^5.1.0",
"fs-plus": "^3.0.0",
"open": "^0.0.5",
"request": "^2.81.0",
"semver": "^5.3.0",
"tar": "^2.2.1",
"tmp": "^0.0.31"
}
}
74 changes: 74 additions & 0 deletions src/commands/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Copyright (c) 2016-present, PlatformIO Plus <[email protected]>
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/

import { runPioCommand } from '../utils';
import vscode from 'vscode';

export default async function initCommand() {
if (!vscode.workspace.rootPath) {
vscode.window.showWarningMessage(
'PlatformIO projec could not be initialized. Please open a folder '
+ 'first before performing initialization.'
);
}
await vscode.window.withProgress({
title: 'PlatformIO Project initialization',
location: vscode.ProgressLocation.Window,
}, async (progress) => {
progress.report({
message: 'Updating a list of avaialbe boards',
});

try {
const data = JSON.parse(await new Promise((resolve, reject) => {
runPioCommand(['boards', '--json-output'], (code, stdout, stderr) => {
if (code !== 0) {
reject(stderr);
} else {
resolve(stdout);
}
});
}));
const items = data.map((board) => ({
label: board.name,
description: board.vendor,
detail: board.mcu,
boardId: board.id,
}));

progress.report({
message: 'Selecting a board',
});
const selectedBoard = await vscode.window.showQuickPick(items, {
ignoreFocusOut: true,
matchOnDescription: true,
matchOnDetail: true,
placeHolder: 'Select a board',
});

if (selectedBoard) {
progress.report({
message: 'Performing initialization',
});

await new Promise((resolve, reject) => {
runPioCommand(['init', '--board', selectedBoard.boardId, '--project-dir', vscode.workspace.rootPath], (code, stdout, stderr) => {
if (code !== 0) {
reject(stderr);
} else {
resolve(stdout);
}
});
});
}
} catch (error) {
console.error(error);
vscode.window.showErrorMessage(error);
}
});
}
35 changes: 35 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (c) 2016-present, PlatformIO Plus <[email protected]>
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/

import fs from 'fs-plus';
import path from 'path';

export const DEFAULT_PIO_ARGS = ['-f'];
export const AUTO_REBUILD_DELAY = 3000;
export const IS_WINDOWS = process.platform.startsWith('win');
export const PIO_HOME_DIR = _getPioHomeDir(process.env.PLATFORMIO_HOME_DIR || path.join(fs.getHomeDirectory(), '.platformio'));
export const ENV_DIR = path.join(PIO_HOME_DIR, 'penv');
export const ENV_BIN_DIR = path.join(ENV_DIR, IS_WINDOWS ? 'Scripts' : 'bin');
export const PIO_CORE_MIN_VERSION = '3.4.0-b.1';

function _getPioHomeDir(pioHomeDir) {
if (IS_WINDOWS) {
// Make sure that all path characters have valid ASCII codes.
for (const char of pioHomeDir) {
if (char.charCodeAt(0) > 127) {
// If they don't, put the pio home directory into the root of the disk.
const homeDirPathFormat = path.parse(pioHomeDir);
return path.format({
dir: homeDirPathFormat.root,
base: '.platformio',
});
}
}
}
return pioHomeDir;
}
99 changes: 99 additions & 0 deletions src/extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* Copyright (c) 2016-present, PlatformIO Plus <[email protected]>
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/

import { ensureDirExists } from './utils';

import InstallationManager from './installer/manager';
import ProjectIndexer from './project/indexer';
import initCommand from './commands/init';
import path from 'path';
import semver from 'semver';
import vscode from 'vscode';

export default class PlatformIOVSCodeExtension {

constructor() {
this.activate = this.activate.bind(this);

const min = 100;
const max = 999;
this.instanceId = Math.floor(Math.random() * (max - min)) + min;
}

async activate(context) {
if (!vscode.workspace.rootPath) {
return;
}

const ext = vscode.extensions.getExtension('platformio.platformio-ide');
const isPrerelease = Boolean(semver.prerelease(ext.packageJSON.version));

await this.startInstaller(context.globalState, context.extensionPath, isPrerelease);

const indexer = new ProjectIndexer(vscode.workspace.rootPath);
context.subscriptions.push(indexer);
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(() => indexer.toggle()));

await indexer.toggle();

context.subscriptions.push(
vscode.commands.registerCommand(
'platformio-ide.init-project',
initCommand)
);

context.subscriptions.push(
vscode.commands.registerCommand(
'platformio-ide.rebuild-index',
() => indexer.doRebuild({
verbose: true,
}))
);
}

startInstaller(globalState, extensionPath, isPrerelease) {
return vscode.window.withProgress({
location: vscode.ProgressLocation.Window,
title: 'PlatformIO',
}, async (progress) => {
progress.report({
message: 'Verifying PlatformIO Core installation...',
});

const cacheDir = path.join(extensionPath, '.cache');
await ensureDirExists(cacheDir);

const config = vscode.workspace.getConfiguration('platformio-ide');
const im = new InstallationManager(globalState, config, cacheDir, isPrerelease);

if (im.locked()) {
vscode.window.showInformationMessage(
'PlatformIO IDE installation has been suspended, because PlatformIO '
+ 'IDE Installer is already started in another window.');
} else if (await im.check()) {
return;
} else {
progress.report({
message: 'Installing PlatformIO IDE...',
});
try {
im.lock();
await im.install();
} catch (err) {
vscode.window.showErrorMessage(err.toString(), {
modal: true,
});
} finally {
im.unlock();
}
}
im.destroy();
return Promise.reject(null);
});
}
}
Loading

0 comments on commit 3e49514

Please sign in to comment.