From 23fea92ae913de690e416aeb046bb35435de0a21 Mon Sep 17 00:00:00 2001 From: Rokas Brazdzionis Date: Fri, 3 Mar 2017 13:42:20 +0200 Subject: [PATCH] Initial commit --- .gitignore | 2 + .vscode/launch.json | 28 +++++++++++++ .vscode/settings.json | 9 +++++ .vscode/tasks.json | 30 ++++++++++++++ .vscodeignore | 9 +++++ CHANGELOG.md | 7 ++++ README.md | 65 ++++++++++++++++++++++++++++++ package.json | 34 ++++++++++++++++ src/angular-definition-provider.ts | 39 ++++++++++++++++++ src/extension.ts | 18 +++++++++ test/extension.test.ts | 22 ++++++++++ test/index.ts | 22 ++++++++++ tsconfig.json | 16 ++++++++ vsc-extension-quickstart.md | 33 +++++++++++++++ 14 files changed, 334 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 .vscodeignore create mode 100644 CHANGELOG.md create mode 100644 README.md create mode 100644 package.json create mode 100644 src/angular-definition-provider.ts create mode 100644 src/extension.ts create mode 100644 test/extension.test.ts create mode 100644 test/index.ts create mode 100644 tsconfig.json create mode 100644 vsc-extension-quickstart.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8e5962e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +out +node_modules \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..cd6b87b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,28 @@ +// A launch configuration that compiles the extension and then opens it inside a new window +{ + "version": "0.1.0", + "configurations": [ + { + "name": "Launch Extension", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": ["--extensionDevelopmentPath=${workspaceRoot}" ], + "stopOnEntry": false, + "sourceMaps": true, + "outFiles": [ "${workspaceRoot}/out/src/**/*.js" ], + "preLaunchTask": "npm" + }, + { + "name": "Launch Tests", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ], + "stopOnEntry": false, + "sourceMaps": true, + "outFiles": [ "${workspaceRoot}/out/test/**/*.js" ], + "preLaunchTask": "npm" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d137133 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +// Place your settings in this file to overwrite default and user settings. +{ + "files.exclude": { + "out": false // set this to true to hide the "out" folder with the compiled JS files + }, + "search.exclude": { + "out": true // set this to false to include "out" folder in search results + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..fb7f662 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,30 @@ +// Available variables which can be used inside of strings. +// ${workspaceRoot}: the root folder of the team +// ${file}: the current opened file +// ${fileBasename}: the current opened file's basename +// ${fileDirname}: the current opened file's dirname +// ${fileExtname}: the current opened file's extension +// ${cwd}: the current working directory of the spawned process + +// A task runner that calls a custom npm script that compiles the extension. +{ + "version": "0.1.0", + + // we want to run npm + "command": "npm", + + // the command is a shell script + "isShellCommand": true, + + // show the output window only if unrecognized errors occur. + "showOutput": "silent", + + // we run the custom script "compile" as defined in package.json + "args": ["run", "compile", "--loglevel", "silent"], + + // The tsc compiler is started in watching mode + "isWatching": true, + + // use the standard tsc in watch mode problem matcher to find compile problems in the output. + "problemMatcher": "$tsc-watch" +} \ No newline at end of file diff --git a/.vscodeignore b/.vscodeignore new file mode 100644 index 0000000..5ff3c19 --- /dev/null +++ b/.vscodeignore @@ -0,0 +1,9 @@ +.vscode/** +.vscode-test/** +out/test/** +test/** +src/** +**/*.map +.gitignore +tsconfig.json +vsc-extension-quickstart.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..29988da --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# Change Log +All notable changes to the "vscode-angular-editor" 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 \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..7b9176f --- /dev/null +++ b/README.md @@ -0,0 +1,65 @@ +# vscode-angular-editor README + +This is the README for your extension "vscode-angular-editor". After writing up a brief description, we recommend including the following sections. + +## Features + +Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file. + +For example if there is an image subfolder under your extension project workspace: + +\!\[feature X\]\(images/feature-x.png\) + +> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow. + +## Requirements + +If you have any requirements or dependencies, add a section describing those and how to install and configure them. + +## Extension Settings + +Include if your extension adds any VS Code settings through the `contributes.configuration` extension point. + +For example: + +This extension contributes the following settings: + +* `myExtension.enable`: enable/disable this extension +* `myExtension.thing`: set to `blah` to do something + +## Known Issues + +Calling out known issues can help limit users opening duplicate issues against your extension. + +## Release Notes + +Users appreciate release notes as you update your extension. + +### 1.0.0 + +Initial release of ... + +### 1.0.1 + +Fixed issue #. + +### 1.1.0 + +Added features X, Y, and Z. + +----------------------------------------------------------------------------------------------------------- + +## Working with Markdown + +**Note:** You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts: + +* Split the editor (`Cmd+\` on OSX or `Ctrl+\` on Windows and Linux) +* Toggle preview (`Shift+CMD+V` on OSX or `Shift+Ctrl+V` on Windows and Linux) +* Press `Ctrl+Space` (Windows, Linux) or `Cmd+Space` (OSX) to see a list of Markdown snippets + +### For more information + +* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown) +* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/) + +**Enjoy!** \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..82c8d2c --- /dev/null +++ b/package.json @@ -0,0 +1,34 @@ +{ + "name": "vscode-angular-editor", + "displayName": "Angular Editor", + "description": "Editing Evolved with Angular", + "version": "0.0.1", + "publisher": "dzonatan", + "engines": { + "vscode": "^1.10.0" + }, + "categories": [ + "Other" + ], + "activationEvents": [ + "onLanguage:typescript", + "onLanguage:javascript" + ], + "main": "./out/src/extension", + "contributes": { + "commands": [] + }, + "scripts": { + "vscode:prepublish": "tsc -p ./", + "compile": "tsc -watch -p ./", + "postinstall": "node ./node_modules/vscode/bin/install", + "test": "node ./node_modules/vscode/bin/test" + }, + "devDependencies": { + "typescript": "^2.0.3", + "vscode": "^1.0.0", + "mocha": "^2.3.3", + "@types/node": "^6.0.40", + "@types/mocha": "^2.2.32" + } +} \ No newline at end of file diff --git a/src/angular-definition-provider.ts b/src/angular-definition-provider.ts new file mode 100644 index 0000000..6f02400 --- /dev/null +++ b/src/angular-definition-provider.ts @@ -0,0 +1,39 @@ +import { + CancellationToken, Position, DefinitionProvider, + TextDocument, Definition, Location, Uri +} from 'vscode'; +import * as path from 'path'; +import * as fs from 'fs'; + +export class AngularDefinitionProvider implements DefinitionProvider { + + provideDefinition(document: TextDocument, position: Position, token: CancellationToken): Definition { + // Apply this definition only on specific lines + const linesFilter = ['templateUrl', 'styleUrls']; + const lineText = document.lineAt(position).text; + if (linesFilter.every(l => lineText.indexOf(l) === -1)) { + return null; + } + + // Parse potential file name + const fileNameRegex = /([\w\.\/\-]+)/; + const potentialFileNameRange = document.getWordRangeAtPosition(position, fileNameRegex); + if (!potentialFileNameRange) { + return null; + } + + const potentialFileName = document.getText(potentialFileNameRange); + const workingDir = path.dirname(document.fileName); + const fullPath = path.resolve(workingDir, potentialFileName); + + console.log('## Potential findings ##'); + console.log("File name: " + potentialFileName); + console.log("Path: " + fullPath); + + if (fs.existsSync(fullPath)) { + return new Location(Uri.file(fullPath), new Position(0, 1)); + } + + return null; + } +} \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts new file mode 100644 index 0000000..6b3df2b --- /dev/null +++ b/src/extension.ts @@ -0,0 +1,18 @@ +'use strict'; + +import { ExtensionContext, DocumentFilter, languages } from 'vscode'; +import { AngularDefinitionProvider } from './angular-definition-provider'; + +export function activate(context: ExtensionContext) { + console.log('Congratulations, your extension "vscode-angular-editor" is now active!'); + + const angularFilter: DocumentFilter[] = [ + { language: 'typescript', scheme: 'file' }, + { language: 'javascript', scheme: 'file' }, + ]; + context.subscriptions.push(languages.registerDefinitionProvider(angularFilter, new AngularDefinitionProvider())); +} + +// this method is called when your extension is deactivated +export function deactivate() { +} \ No newline at end of file diff --git a/test/extension.test.ts b/test/extension.test.ts new file mode 100644 index 0000000..5c4a4da --- /dev/null +++ b/test/extension.test.ts @@ -0,0 +1,22 @@ +// +// Note: This example test is leveraging the Mocha test framework. +// Please refer to their documentation on https://mochajs.org/ for help. +// + +// The module 'assert' provides assertion methods from node +import * as assert from 'assert'; + +// You can import and use all API from the 'vscode' module +// as well as import your extension to test it +import * as vscode from 'vscode'; +import * as myExtension from '../src/extension'; + +// Defines a Mocha test suite to group tests of similar kind together +suite("Extension Tests", () => { + + // Defines a Mocha unit test + test("Something 1", () => { + assert.equal(-1, [1, 2, 3].indexOf(5)); + assert.equal(-1, [1, 2, 3].indexOf(0)); + }); +}); \ No newline at end of file diff --git a/test/index.ts b/test/index.ts new file mode 100644 index 0000000..50bae45 --- /dev/null +++ b/test/index.ts @@ -0,0 +1,22 @@ +// +// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING +// +// This file is providing the test runner to use when running extension tests. +// By default the test runner in use is Mocha based. +// +// You can provide your own test runner if you want to override it by exporting +// a function run(testRoot: string, clb: (error:Error) => void) that the extension +// host can call to run the tests. The test runner is expected to use console.log +// to report the results back to the caller. When the tests are finished, return +// a possible error to the callback or null if none. + +var testRunner = require('vscode/lib/testrunner'); + +// You can directly control Mocha options by uncommenting the following lines +// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info +testRunner.configure({ + ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.) + useColors: true // colored output from test results +}); + +module.exports = testRunner; \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..11282c9 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "outDir": "out", + "lib": [ + "es6" + ], + "sourceMap": true, + "rootDir": "." + }, + "exclude": [ + "node_modules", + ".vscode-test" + ] +} \ No newline at end of file diff --git a/vsc-extension-quickstart.md b/vsc-extension-quickstart.md new file mode 100644 index 0000000..6cdea2b --- /dev/null +++ b/vsc-extension-quickstart.md @@ -0,0 +1,33 @@ +# Welcome to your first VS Code Extension + +## What's in the folder +* This folder contains all of the files necessary for your extension +* `package.json` - this is the manifest file in which you declare your extension and command. +The sample plugin registers a command and defines its title and command name. With this information +VS Code can show the command in the command palette. It doesn’t yet need to load the plugin. +* `src/extension.ts` - this is the main file where you will provide the implementation of your command. +The file exports one function, `activate`, which is called the very first time your extension is +activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`. +We pass the function containing the implementation of the command as the second parameter to +`registerCommand`. + +## Get up and running straight away +* press `F5` to open a new window with your extension loaded +* run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World` +* set breakpoints in your code inside `src/extension.ts` to debug your extension +* find output from your extension in the debug console + +## Make changes +* you can relaunch the extension from the debug toolbar after changing code in `src/extension.ts` +* you can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes + +## Explore the API +* you can open the full set of our API when you open the file `node_modules/vscode/vscode.d.ts` + +## Run tests +* open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Launch Tests` +* press `F5` to run the tests in a new window with your extension loaded +* see the output of the test result in the debug console +* make changes to `test/extension.test.ts` or create new test files inside the `test` folder + * by convention, the test runner will only consider files matching the name pattern `**.test.ts` + * you can create folders inside the `test` folder to structure your tests any way you want \ No newline at end of file