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

feat(language-service): add services to support editors #12987

Merged
merged 1 commit into from Nov 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sh
Expand Up @@ -17,6 +17,7 @@ PACKAGES=(core
upgrade
router
compiler-cli
language-service
benchpress)
BUILD_ALL=true
BUNDLE=true
Expand Down Expand Up @@ -184,7 +185,6 @@ do
mv ${UMD_ES5_PATH}.tmp ${UMD_ES5_PATH}
$UGLIFYJS -c --screw-ie8 --comments -o ${UMD_ES5_MIN_PATH} ${UMD_ES5_PATH}


if [[ -e rollup-testing.config.js ]]; then
echo "====== Rollup ${PACKAGE} testing"
../../../node_modules/.bin/rollup -c rollup-testing.config.js
Expand Down
1 change: 1 addition & 0 deletions karma-js.conf.js
Expand Up @@ -52,6 +52,7 @@ module.exports = function(config) {
'dist/all/@angular/compiler-cli/**',
'dist/all/@angular/compiler/test/aot/**',
'dist/all/@angular/benchpress/**',
'dist/all/@angular/language-service/**',
'dist/all/angular1_router.js',
'dist/all/@angular/platform-browser/testing/e2e_util.js',
'dist/examples/**/e2e_test/**',
Expand Down
22 changes: 22 additions & 0 deletions modules/@angular/language-service/index.ts
@@ -0,0 +1,22 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

/**
* @module
* @description
* Entry point for all public APIs of the language service package.
*/
import * as ts from 'typescript';

import {LanguageServicePlugin} from './src/ts_plugin';

export {createLanguageService} from './src/language_service';
export {Completion, Completions, Declaration, Declarations, Definition, Diagnostic, Diagnostics, Hover, HoverTextSection, LanguageService, LanguageServiceHost, Location, Span, TemplateSource, TemplateSources} from './src/types';
export {TypeScriptServiceHost, createLanguageServiceFromTypescript} from './src/typescript_host';

export default LanguageServicePlugin;
14 changes: 14 additions & 0 deletions modules/@angular/language-service/package.json
@@ -0,0 +1,14 @@
{
"name": "@angular/language-service",
"version": "0.0.0-PLACEHOLDER",
"description": "Angular 2 - language services",
"main": "bundles/language-service.umd.js",
"module": "index.js",
"typings": "index.d.ts",
"author": "angular",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/angular/angular.git"
}
}
81 changes: 81 additions & 0 deletions modules/@angular/language-service/rollup.config.js
@@ -0,0 +1,81 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import commonjs from 'rollup-plugin-commonjs';
import * as path from 'path';

var m = /^\@angular\/((\w|\-)+)(\/(\w|\d|\/|\-)+)?$/;
var location = normalize('../../../dist/packages-dist') + '/';
var rxjsLocation = normalize('../../../node_modules/rxjs');
var esm = 'esm/';

var locations = {
'tsc-wrapped': normalize('../../../dist/tools/@angular') + '/',
};

var esm_suffixes = {};

function normalize(fileName) {
return path.resolve(__dirname, fileName);
}

function resolve(id, from) {
// console.log('Resolve id:', id, 'from', from)
if (id == '@angular/tsc-wrapped') {
// Hack to restrict the import to not include the index of @angular/tsc-wrapped so we don't
// rollup tsickle.
return locations['tsc-wrapped'] + 'tsc-wrapped/src/collector.js';
}
var match = m.exec(id);
if (match) {
var packageName = match[1];
var esm_suffix = esm_suffixes[packageName] || '';
var loc = locations[packageName] || location;
var r = loc + esm_suffix + packageName + (match[3] || '/index') + '.js';
// console.log('** ANGULAR MAPPED **: ', r);
return r;
}
if (id && id.startsWith('rxjs/')) {
const resolved = `${rxjsLocation}${id.replace('rxjs', '')}.js`;
return resolved;
}
}

var banner = `
var $deferred, $resolved, $provided;
function $getModule(name) { return $provided[name] || require(name); }
function define(modules, cb) { $deferred = { modules: modules, cb: cb }; }
module.exports = function(provided) {
if ($resolved) return $resolved;
var result = {};
$provided = Object.assign({}, provided || {}, { exports: result });
$deferred.cb.apply(this, $deferred.modules.map($getModule));
$resolved = result;
return result;
}
`;

export default {
entry: '../../../dist/packages-dist/language-service/index.js',
dest: '../../../dist/packages-dist/language-service/bundles/language-service.umd.js',
format: 'amd',
moduleName: 'ng.language_service',
exports: 'named',
external: [
'fs',
'path',
'typescript',
],
globals: {
'typescript': 'ts',
'path': 'path',
'fs': 'fs',
},
banner: banner,
plugins: [{resolveId: resolve}, commonjs()]
}
29 changes: 29 additions & 0 deletions modules/@angular/language-service/src/ast_path.ts
@@ -0,0 +1,29 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

export class AstPath<T> {
constructor(private path: T[]) {}

get empty(): boolean { return !this.path || !this.path.length; }
get head(): T|undefined { return this.path[0]; }
get tail(): T|undefined { return this.path[this.path.length - 1]; }

parentOf(node: T): T|undefined { return this.path[this.path.indexOf(node) - 1]; }
childOf(node: T): T|undefined { return this.path[this.path.indexOf(node) + 1]; }

first<N extends T>(ctor: {new (...args: any[]): N}): N|undefined {
for (let i = this.path.length - 1; i >= 0; i--) {
let item = this.path[i];
if (item instanceof ctor) return <N>item;
}
}

push(node: T) { this.path.push(node); }

pop(): T { return this.path.pop(); }
}
53 changes: 53 additions & 0 deletions modules/@angular/language-service/src/common.ts
@@ -0,0 +1,53 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import {CompileDirectiveMetadata, CompileDirectiveSummary, CompilePipeSummary} from '@angular/compiler';

import {Parser} from '@angular/compiler/src/expression_parser/parser';
import {Node as HtmlAst} from '@angular/compiler/src/ml_parser/ast';
import {ParseError} from '@angular/compiler/src/parse_util';
import {CssSelector} from '@angular/compiler/src/selector';
import {TemplateAst} from '@angular/compiler/src/template_parser/template_ast';

import {Diagnostic, TemplateSource} from './types';

export interface AstResult {
htmlAst?: HtmlAst[];
templateAst?: TemplateAst[];
directive?: CompileDirectiveMetadata;
directives?: CompileDirectiveSummary[];
pipes?: CompilePipeSummary[];
parseErrors?: ParseError[];
expressionParser?: Parser;
errors?: Diagnostic[];
}

export interface TemplateInfo {
position?: number;
fileName?: string;
template: TemplateSource;
htmlAst: HtmlAst[];
directive: CompileDirectiveMetadata;
directives: CompileDirectiveSummary[];
pipes: CompilePipeSummary[];
templateAst: TemplateAst[];
expressionParser: Parser;
}

export interface AttrInfo {
name: string;
input?: boolean;
output?: boolean;
template?: boolean;
fromHtml?: boolean;
}

export type SelectorInfo = {
selectors: CssSelector[],
map: Map<CssSelector, CompileDirectiveSummary>
};