Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 341247c

Browse files
authored
Merge pull request #1 from Microsoft/yaohai_dev
Initialize VSCode extension for Arduino.
2 parents 7389698 + f177f39 commit 341247c

18 files changed

+350
-0
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Tab indentation
7+
[*]
8+
indent_style = space
9+
indent_size = 4
10+
11+
# The indent size used in the `package.json` file cannot be changed
12+
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
13+
[{.travis.yml,npm-shrinkwrap.json,package.json}]
14+
indent_size = 2

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
out
2+
node_modules
3+
.vscode-test

.vscode/launch.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// A launch configuration that compiles the extension and then opens it inside a new window
2+
{
3+
"version": "0.1.0",
4+
"configurations": [
5+
{
6+
"name": "Launch Extension",
7+
"type": "extensionHost",
8+
"request": "launch",
9+
"runtimeExecutable": "${execPath}",
10+
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
11+
"stopOnEntry": false,
12+
"sourceMaps": true,
13+
"outFiles": [ "${workspaceRoot}/out/src/**/*.js" ],
14+
"preLaunchTask": "npm"
15+
},
16+
{
17+
"name": "Launch Tests",
18+
"type": "extensionHost",
19+
"request": "launch",
20+
"runtimeExecutable": "${execPath}",
21+
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
22+
"stopOnEntry": false,
23+
"sourceMaps": true,
24+
"outFiles": [ "${workspaceRoot}/out/test/**/*.js" ],
25+
"preLaunchTask": "npm"
26+
}
27+
]
28+
}

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"files.exclude": {
4+
"out": false // set this to true to hide the "out" folder with the compiled JS files
5+
},
6+
"search.exclude": {
7+
"out": true // set this to false to include "out" folder in search results
8+
},
9+
"typescript.tsdk": "./node_modules/typescript/lib" // we want to use the TS server from our node_modules folder to control its version
10+
}

.vscode/tasks.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Available variables which can be used inside of strings.
2+
// ${workspaceRoot}: the root folder of the team
3+
// ${file}: the current opened file
4+
// ${fileBasename}: the current opened file's basename
5+
// ${fileDirname}: the current opened file's dirname
6+
// ${fileExtname}: the current opened file's extension
7+
// ${cwd}: the current working directory of the spawned process
8+
9+
// A task runner that calls a custom npm script that compiles the extension.
10+
{
11+
"version": "0.1.0",
12+
13+
// we want to run npm
14+
"command": "npm",
15+
16+
// the command is a shell script
17+
"isShellCommand": true,
18+
19+
// show the output window only if unrecognized errors occur.
20+
"showOutput": "silent",
21+
22+
// we run the custom script "compile" as defined in package.json
23+
"args": ["run", "compile", "--loglevel", "silent"],
24+
25+
// The tsc compiler is started in watching mode
26+
"isWatching": true,
27+
28+
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
29+
"problemMatcher": "$tsc-watch"
30+
}

.vscodeignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.vscode/**
2+
.vscode-test/**
3+
out/test/**
4+
test/**
5+
src/**
6+
**/*.map
7+
.gitignore
8+
tsconfig.json

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Change Log
2+
All notable changes to the "vscode-arduino" extension will be documented in this file.
3+
4+
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
5+
6+
## [Unreleased]
7+
- Initial release

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Visual Studio Code Extension for Arduino

gulpfile.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const gulp = require('gulp');
2+
const tslint = require('gulp-tslint');
3+
//...
4+
gulp.task('tslint', () => {
5+
return gulp.src(['**/*.ts', '!**/*.d.ts', '!node_modules/**'])
6+
.pipe(tslint())
7+
.pipe(tslint.report());
8+
});

package.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "vscode-arduino",
3+
"displayName": "vscode-arduino",
4+
"description": "Visual Studio Code Extension for Arduino",
5+
"version": "0.0.1",
6+
"publisher": "Microsoft",
7+
"engines": {
8+
"vscode": "^1.5.0"
9+
},
10+
"categories": [
11+
"Languages",
12+
"Snippets"
13+
],
14+
"activationEvents": [
15+
"onCommand:extension.verifyArduino",
16+
"onCommand:extension.uploadArduino"
17+
],
18+
"main": "./out/src/extension",
19+
"contributes": {
20+
"commands": [
21+
{
22+
"command": "extension.verifyArduino",
23+
"title": "Arduino: verfiy"
24+
},
25+
{
26+
"command": "extension.uploadArduino",
27+
"title": "Arduino: upload"
28+
}
29+
],
30+
"configuration": {
31+
"type": "object",
32+
"title": "Arduino configuration",
33+
"properties": {
34+
"arduino.path": {
35+
"type": "string",
36+
"default": "arduino",
37+
"description": "Path to Arduino, you can use a custom version of Arduino by modifying this setting to include the full path."
38+
}
39+
}
40+
}
41+
},
42+
"scripts": {
43+
"vscode:prepublish": "tsc -p ./",
44+
"compile": "tsc -watch -p ./",
45+
"postinstall": "node ./node_modules/vscode/bin/install",
46+
"test": "node ./node_modules/vscode/bin/test"
47+
},
48+
"devDependencies": {
49+
"@types/mocha": "^2.2.32",
50+
"@types/node": "^6.0.40",
51+
"gulp": "^3.9.1",
52+
"gulp-tslint": "^7.0.1",
53+
"mocha": "^2.3.3",
54+
"tslint": "^4.2.0",
55+
"typescript": "^2.0.3",
56+
"vscode": "^1.0.0"
57+
}
58+
}

src/arduino/arduino.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
import vscode = require('vscode');
4+
import settings = require('./settings');
5+
6+
export function verify(arduinoConfig: settings.IArduinoSettings) {
7+
vscode.window.showInformationMessage(arduinoConfig.arduinoPath);
8+
return 'verify';
9+
}
10+
11+
export function upload(arduinoConfig: settings.IArduinoSettings) {
12+
vscode.window.showInformationMessage(arduinoConfig.arduinoPath);
13+
return 'upload';
14+
}

src/arduino/settings.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
'use strict';
2+
3+
import * as vscode from 'vscode';
4+
import * as path from 'path';
5+
import * as fsHelper from '../helper/fsHelper';
6+
7+
export const IS_WINDOWS = /^win/.test(process.platform);
8+
9+
export interface IArduinoSettings {
10+
arduinoPath: string;
11+
}
12+
13+
export class ArduinoSettings implements IArduinoSettings {
14+
private static arduinoSettings: ArduinoSettings = new ArduinoSettings();
15+
constructor() {
16+
this.initializeSettings();
17+
}
18+
19+
public static getIntance(): ArduinoSettings {
20+
return ArduinoSettings.arduinoSettings;
21+
}
22+
23+
private initializeSettings() {
24+
let arduinoConfig = vscode.workspace.getConfiguration('arduino');
25+
this.arduinoPath = arduinoConfig.get<string>('arduinoPath');
26+
}
27+
28+
private _arduinoPath: string;
29+
30+
public get arduinoPath(): string {
31+
return this._arduinoPath;
32+
}
33+
34+
public set arduinoPath(value: string) {
35+
if (this._arduinoPath === value) {
36+
return;
37+
}
38+
try {
39+
this._arduinoPath = getArduinoExecutable(value);
40+
}
41+
catch (ex) {
42+
this._arduinoPath = value;
43+
}
44+
}
45+
}
46+
47+
function getArduinoExecutable(arduinoPath: string): string {
48+
if (arduinoPath === 'arduino' || fsHelper.fileExists(arduinoPath)) {
49+
return arduinoPath;
50+
}
51+
52+
if (IS_WINDOWS) {
53+
if (fsHelper.fileExists(path.join(arduinoPath, 'arduino.exe'))) {
54+
return path.join(arduinoPath, 'arduino.exe');
55+
}
56+
} else {
57+
if (fsHelper.fileExists(path.join(arduinoPath, 'arduino'))) {
58+
return path.join(arduinoPath, 'arduino');
59+
}
60+
}
61+
return arduinoPath;
62+
}

src/extension.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
import vscode = require('vscode');
4+
import * as settings from './arduino/settings';
5+
import { verify, upload } from './arduino/arduino';
6+
7+
// this method is called when your extension is activated
8+
// your extension is activated the very first time the command is executed
9+
export function activate(context: vscode.ExtensionContext) {
10+
11+
let arduinoSettings = settings.ArduinoSettings.getIntance();
12+
13+
vscode.commands.registerCommand('extension.verifyArduino', () => {
14+
return verify(arduinoSettings);
15+
});
16+
17+
vscode.commands.registerCommand('extension.uploadArduino', () => {
18+
return upload(arduinoSettings);
19+
});
20+
}
21+
22+
// this method is called when your extension is deactivated
23+
export function deactivate() {
24+
}

src/helper/fsHelper.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
import fs = require('fs');
4+
5+
export function fileExists(filePath: string): boolean {
6+
try {
7+
return fs.statSync(filePath).isFile();
8+
} catch (e) {
9+
return false;
10+
}
11+
}

test/extension.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// Note: This example test is leveraging the Mocha test framework.
3+
// Please refer to their documentation on https://mochajs.org/ for help.
4+
//
5+
import * as assert from 'assert';
6+
import * as vscode from 'vscode';
7+
8+
// Defines a Mocha test suite to group tests of similar kind together
9+
suite("Arduino Extension Tests", () => {
10+
11+
test('Verify command', (done) => {
12+
vscode.commands.executeCommand('extension.verifyArduino')
13+
.then(result => assert(result === 'verify', 'Failed to verify Arduino app'))
14+
.then(done, done);
15+
});
16+
17+
test('Upload Arduino command', (done) => {
18+
vscode.commands.executeCommand('extension.uploadArduino')
19+
.then(result => assert(result === 'upload', 'Failed to upload arduino app'))
20+
.then(done, done);
21+
});
22+
});

test/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
3+
//
4+
// This file is providing the test runner to use when running extension tests.
5+
// By default the test runner in use is Mocha based.
6+
//
7+
// You can provide your own test runner if you want to override it by exporting
8+
// a function run(testRoot: string, clb: (error:Error) => void) that the extension
9+
// host can call to run the tests. The test runner is expected to use console.log
10+
// to report the results back to the caller. When the tests are finished, return
11+
// a possible error to the callback or null if none.
12+
13+
var testRunner = require('vscode/lib/testrunner');
14+
15+
// You can directly control Mocha options by uncommenting the following lines
16+
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
17+
testRunner.configure({
18+
ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
19+
useColors: true // colored output from test results
20+
});
21+
22+
module.exports = testRunner;

tsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es6",
5+
"outDir": "out",
6+
"lib": [
7+
"es6"
8+
],
9+
"sourceMap": true,
10+
"rootDir": "."
11+
},
12+
"exclude": [
13+
"node_modules",
14+
".vscode-test"
15+
]
16+
}

tslint.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"rules": {
3+
"no-unused-expression": true,
4+
"no-duplicate-variable": true,
5+
"curly": true,
6+
"class-name": true,
7+
"semicolon": [
8+
"always"
9+
],
10+
"triple-equals": true
11+
}
12+
}

0 commit comments

Comments
 (0)