提交 d6659f6d 编写于 作者: A Alex Dima

Reduce standalone editor API through @internal markers

上级 462bdd37
此差异已折叠。
// TODO@Alex: Remove EventType, EmitterEvent, ListenerCallback, BulkListenerCallback, IEventEmitter
declare module monaco.editor {
export function create(domElement: HTMLElement, options: IEditorConstructionOptions, services?: any): ICodeEditor;
......@@ -7,7 +9,7 @@ declare module monaco.editor {
export function createCustomMode(description:ILanguage): TPromise<IMode>;
export function colorize(text: string, modeId: string, options: IColorizerOptions): TPromise<string>;
export function colorizeElement(domNode: HTMLElement, options: IColorizerElementOptions): TPromise<void>;
export function colorizeLine(line: string, tokens: ViewLineToken[], tabSize?: number): string;
// export function colorizeLine(line: string, tokens: ViewLineToken[], tabSize?: number): string;
export function colorizeModelLine(model: IModel, lineNumber: number, tabSize?: number): string;
export function registerWorkerParticipant(modeId:string, moduleName:string, ctorName:string): void;
export function configureMode(modeId: string, options: any): void;
......@@ -51,72 +53,43 @@ declare module monaco {
dispose(): void;
}
export interface IEvent<T> {
(listener: (e: T) => any, thisArg?: any): IDisposable;
}
export class Emitter<T> {
constructor();
event: IEvent<T>;
fire(event?: T): void;
dispose(): void;
}
#include(vs/base/common/winjs.base.d.ts): TValueCallback, ProgressCallback, TPromise
#include(vs/base/common/uri): URI
#include(vs/base/common/eventEmitter): EmitterEvent, ListenerCallback, BulkListenerCallback, IEventEmitter
#include(vs/base/common/keyCodes): KeyCode, KeyMod
#include(vs/base/common/winjs.base.d.ts): TValueCallback, ProgressCallback, TPromise
#include(vs/base/common/htmlContent): IHTMLContentElementCode, IHTMLContentElement
#include(vs/base/common/uri): URI
#include(vs/base/common/actions): IAction
// TODO@Alex: START remove this
#include(vs/base/common/eventEmitter): EmitterEvent, ListenerCallback, BulkListenerCallback, IEventEmitter
// TODO@Alex: END remove this
#include(vs/base/browser/keyboardEvent): IKeyboardEvent
#include(vs/base/common/keyCodes): KeyCode, KeyMod
#include(vs/base/browser/mouseEvent): IMouseEvent
#include(vs/base/common/htmlContent): IHTMLContentElementCode, IHTMLContentElement
export interface IPlatformServices {
}
#include(vs/base/common/actions): IAction
export interface IInstantiationService {
}
#include(vs/base/browser/keyboardEvent): IKeyboardEvent
#include(vs/base/browser/mouseEvent): IMouseEvent
#include(vs/editor/common/editorCommon): IScrollEvent
export interface IConstructorSignature1<A1, T> {
new (context: IPlatformServices, first: A1): T;
}
export interface IConstructorSignature2<A1, A2, T> {
new (context: IPlatformServices, first: A1, second: A2): T;
}
#include(vs/editor/common/editorCommon): IPosition, IRange, SelectionDirection, ISelection
#include(vs/editor/common/core/position): Position
#include(vs/editor/common/core/range): Range
#include(vs/editor/common/core/selection): Selection
#include(vs/editor/common/editorCommon): IPosition, IRange, SelectionDirection, ISelection
#include(vs/editor/common/core/position): Position
#include(vs/editor/common/core/range): Range
#include(vs/editor/common/core/selection): Selection
}
declare module monaco.editor {
#include(vs/editor/common/modes/monarch/monarchTypes): ILanguage, ILanguageBracket
#include(vs/editor/common/core/modeTransition): ModeTransition
#include(vs/editor/common/modes): IToken, IModeTransition, ILineContext
#include(vs/editor/common/modes/monarch/monarchTypes): ILanguage, ILanguageBracket
export interface IMode {
}
#include(vs/base/browser/ui/scrollbar/scrollableElementOptions): ScrollbarVisibility
#include(vs/editor/common/core/viewLineToken): ViewLineToken
#include(vs/base/browser/ui/scrollbar/scrollableElementOptions): ScrollbarVisibility
#includeAll(vs/editor/common/editorCommon): IPosition, IRange, SelectionDirection, ISelection, IFoundBracket
#includeAll(vs/editor/common/editorCommon): IPosition, IRange, ISelection, SelectionDirection, IScrollEvent
#includeAll(vs/editor/browser/editorBrowser):
#includeAll(vs/editor/browser/editorBrowser):
}
\ No newline at end of file
......@@ -28,8 +28,11 @@ function getSourceFile(moduleId) {
return SOURCE_FILE_MAP[moduleId];
}
function isDeclaration(a) {
var tmp = a;
return tmp.name && typeof tmp.name.text === 'string';
return (a.kind === ts.SyntaxKind.InterfaceDeclaration
|| a.kind === ts.SyntaxKind.EnumDeclaration
|| a.kind === ts.SyntaxKind.ClassDeclaration
|| a.kind === ts.SyntaxKind.TypeAliasDeclaration
|| a.kind === ts.SyntaxKind.FunctionDeclaration);
}
function visitTopLevelDeclarations(sourceFile, visitor) {
var stop = false;
......@@ -45,14 +48,13 @@ function visitTopLevelDeclarations(sourceFile, visitor) {
case ts.SyntaxKind.TypeAliasDeclaration:
case ts.SyntaxKind.FunctionDeclaration:
stop = visitor(node);
break;
}
if (node.kind !== ts.SyntaxKind.SourceFile) {
if (getNodeText(sourceFile, node).indexOf('cursorStyleToString') >= 0) {
console.log('FOUND TEXT IN NODE: ' + ts.SyntaxKind[node.kind]);
console.log(getNodeText(sourceFile, node));
}
}
// if (node.kind !== ts.SyntaxKind.SourceFile) {
// if (getNodeText(sourceFile, node).indexOf('Handler') >= 0) {
// console.log('FOUND TEXT IN NODE: ' + ts.SyntaxKind[node.kind]);
// console.log(getNodeText(sourceFile, node));
// }
// }
if (stop) {
return;
}
......@@ -63,7 +65,21 @@ function visitTopLevelDeclarations(sourceFile, visitor) {
function getAllTopLevelDeclarations(sourceFile) {
var all = [];
visitTopLevelDeclarations(sourceFile, function (node) {
all.push(node);
if (node.kind === ts.SyntaxKind.InterfaceDeclaration) {
var interfaceDeclaration = node;
var triviaStart = interfaceDeclaration.pos;
var triviaEnd = interfaceDeclaration.name.pos;
var triviaText = getNodeText(sourceFile, { pos: triviaStart, end: triviaEnd });
if (triviaText.indexOf('@internal') === -1) {
all.push(node);
}
}
else {
var nodeText = getNodeText(sourceFile, node);
if (nodeText.indexOf('@internal') === -1) {
all.push(node);
}
}
return false /*continue*/;
});
return all;
......@@ -79,8 +95,15 @@ function getTopLevelDeclaration(sourceFile, typeName) {
return false /*continue*/;
}
// node is ts.VariableStatement
return (getNodeText(sourceFile, node).indexOf(typeName) >= 0);
if (getNodeText(sourceFile, node).indexOf(typeName) >= 0) {
result = node;
return true /*stop*/;
}
return false /*continue*/;
});
if (result === null) {
console.log('COULD NOT FIND ' + typeName + '!');
}
return result;
}
function getNodeText(sourceFile, node) {
......@@ -88,6 +111,21 @@ function getNodeText(sourceFile, node) {
}
function getMassagedTopLevelDeclarationText(sourceFile, declaration) {
var result = getNodeText(sourceFile, declaration);
if (declaration.kind === ts.SyntaxKind.InterfaceDeclaration) {
var interfaceDeclaration = declaration;
var members = interfaceDeclaration.members;
members.forEach(function (member) {
try {
var memberText = getNodeText(sourceFile, member);
if (memberText.indexOf('@internal') >= 0) {
// console.log('BEFORE: ', result);
result = result.replace(memberText, '');
}
}
catch (err) {
}
});
}
result = result.replace(/export default/g, 'export');
result = result.replace(/export declare/g, 'export');
return result;
......@@ -144,6 +182,7 @@ var result = [];
lines.forEach(function (line) {
var m1 = line.match(/^\s*#include\(([^\)]*)\)\:(.*)$/);
if (m1) {
console.log('HANDLING META: ' + line);
var moduleId = m1[1];
var sourceFile_1 = getSourceFile(moduleId);
var typeNames = m1[2].split(/,/);
......@@ -159,24 +198,34 @@ lines.forEach(function (line) {
}
var m2 = line.match(/^\s*#includeAll\(([^\)]*)\)\:(.*)$/);
if (m2) {
console.log('HANDLING META: ' + line);
var moduleId = m2[1];
var sourceFile_2 = getSourceFile(moduleId);
var typeNames = m2[2].split(/,/);
var typesToExclude_1 = {};
var typesToExcludeMap_1 = {};
var typesToExcludeArr_1 = [];
typeNames.forEach(function (typeName) {
typeName = typeName.trim();
if (typeName.length === 0) {
return;
}
typesToExclude_1[typeName] = true;
typesToExcludeMap_1[typeName] = true;
typesToExcludeArr_1.push(typeName);
});
getAllTopLevelDeclarations(sourceFile_2).forEach(function (declaration) {
if (isDeclaration(declaration)) {
if (typesToExclude_1[declaration.name.text]) {
if (typesToExcludeMap_1[declaration.name.text]) {
return;
}
}
else {
// node is ts.VariableStatement
var nodeText = getNodeText(sourceFile_2, declaration);
for (var i = 0; i < typesToExcludeArr_1.length; i++) {
if (nodeText.indexOf(typesToExcludeArr_1[i]) >= 0) {
return;
}
}
}
result.push(getMassagedTopLevelDeclarationText(sourceFile_2, declaration));
});
......
......@@ -42,8 +42,13 @@ type TSTopLevelDeclaration = ts.InterfaceDeclaration | ts.EnumDeclaration | ts.C
type TSTopLevelDeclare = TSTopLevelDeclaration | ts.VariableStatement;
function isDeclaration(a:TSTopLevelDeclare): a is TSTopLevelDeclaration {
let tmp = <TSTopLevelDeclaration>a;
return tmp.name && typeof tmp.name.text === 'string';
return (
a.kind === ts.SyntaxKind.InterfaceDeclaration
|| a.kind === ts.SyntaxKind.EnumDeclaration
|| a.kind === ts.SyntaxKind.ClassDeclaration
|| a.kind === ts.SyntaxKind.TypeAliasDeclaration
|| a.kind === ts.SyntaxKind.FunctionDeclaration
);
}
function visitTopLevelDeclarations(sourceFile:ts.SourceFile, visitor:(node:TSTopLevelDeclare)=>boolean): void {
......@@ -62,15 +67,14 @@ function visitTopLevelDeclarations(sourceFile:ts.SourceFile, visitor:(node:TSTop
case ts.SyntaxKind.TypeAliasDeclaration:
case ts.SyntaxKind.FunctionDeclaration:
stop = visitor(<TSTopLevelDeclare>node);
break;
}
if (node.kind !== ts.SyntaxKind.SourceFile) {
if (getNodeText(sourceFile, node).indexOf('cursorStyleToString') >= 0) {
console.log('FOUND TEXT IN NODE: ' + ts.SyntaxKind[node.kind]);
console.log(getNodeText(sourceFile, node));
}
}
// if (node.kind !== ts.SyntaxKind.SourceFile) {
// if (getNodeText(sourceFile, node).indexOf('Handler') >= 0) {
// console.log('FOUND TEXT IN NODE: ' + ts.SyntaxKind[node.kind]);
// console.log(getNodeText(sourceFile, node));
// }
// }
if (stop) {
return;
......@@ -85,7 +89,20 @@ function visitTopLevelDeclarations(sourceFile:ts.SourceFile, visitor:(node:TSTop
function getAllTopLevelDeclarations(sourceFile:ts.SourceFile): TSTopLevelDeclare[] {
let all:TSTopLevelDeclare[] = [];
visitTopLevelDeclarations(sourceFile, (node) => {
all.push(node);
if (node.kind === ts.SyntaxKind.InterfaceDeclaration) {
let interfaceDeclaration = <ts.InterfaceDeclaration>node;
let triviaStart = interfaceDeclaration.pos;
let triviaEnd = interfaceDeclaration.name.pos;
let triviaText = getNodeText(sourceFile, { pos: triviaStart, end: triviaEnd });
if (triviaText.indexOf('@internal') === -1) {
all.push(node);
}
} else {
let nodeText = getNodeText(sourceFile, node);
if (nodeText.indexOf('@internal') === -1) {
all.push(node);
}
}
return false /*continue*/;
});
return all;
......@@ -103,19 +120,43 @@ function getTopLevelDeclaration(sourceFile:ts.SourceFile, typeName:string): TSTo
return false /*continue*/;
}
// node is ts.VariableStatement
return (getNodeText(sourceFile, node).indexOf(typeName) >= 0);
if (getNodeText(sourceFile, node).indexOf(typeName) >= 0) {
result = node;
return true /*stop*/;
}
return false /*continue*/;
});
if (result === null) {
console.log('COULD NOT FIND ' + typeName + '!');
}
return result;
}
function getNodeText(sourceFile:ts.SourceFile, node:ts.Node): string {
function getNodeText(sourceFile:ts.SourceFile, node:{pos:number; end:number;}): string {
return sourceFile.getFullText().substring(node.pos, node.end);
}
function getMassagedTopLevelDeclarationText(sourceFile:ts.SourceFile, declaration: TSTopLevelDeclare): string {
let result = getNodeText(sourceFile, declaration);
if (declaration.kind === ts.SyntaxKind.InterfaceDeclaration) {
let interfaceDeclaration = <ts.InterfaceDeclaration>declaration;
let members = interfaceDeclaration.members;
members.forEach((member) => {
try {
let memberText = getNodeText(sourceFile, member);
if (memberText.indexOf('@internal') >= 0) {
// console.log('BEFORE: ', result);
result = result.replace(memberText, '');
// console.log('AFTER: ', result);
}
} catch (err) {
// life..
}
});
}
result = result.replace(/export default/g, 'export');
result = result.replace(/export declare/g, 'export');
return result;
......@@ -147,7 +188,7 @@ function format(text:string): string {
for (let i = edits.length - 1; i >= 0; i--) {
let change = edits[i];
let head = result.slice(0, change.span.start);
let tail = result.slice(change.span.start + change.span.length)
let tail = result.slice(change.span.start + change.span.length);
result = head + change.newText + tail;
}
return result;
......@@ -183,6 +224,7 @@ lines.forEach(line => {
let m1 = line.match(/^\s*#include\(([^\)]*)\)\:(.*)$/);
if (m1) {
console.log('HANDLING META: ' + line);
let moduleId = m1[1];
let sourceFile = getSourceFile(moduleId);
......@@ -200,27 +242,38 @@ lines.forEach(line => {
let m2 = line.match(/^\s*#includeAll\(([^\)]*)\)\:(.*)$/);
if (m2) {
console.log('HANDLING META: ' + line);
let moduleId = m2[1];
let sourceFile = getSourceFile(moduleId);
let typeNames = m2[2].split(/,/);
let typesToExclude: {[typeName:string]:boolean;} = {};
let typesToExcludeMap: {[typeName:string]:boolean;} = {};
let typesToExcludeArr: string[] = [];
typeNames.forEach((typeName) => {
typeName = typeName.trim();
if (typeName.length === 0) {
return;
}
typesToExclude[typeName] = true;
typesToExcludeMap[typeName] = true;
typesToExcludeArr.push(typeName);
});
getAllTopLevelDeclarations(sourceFile).forEach((declaration) => {
if (isDeclaration(declaration)) {
if (typesToExclude[declaration.name.text]) {
if (typesToExcludeMap[declaration.name.text]) {
return;
}
} else {
// todo
// node is ts.VariableStatement
let nodeText = getNodeText(sourceFile, declaration);
for (let i = 0; i < typesToExcludeArr.length; i++) {
if (nodeText.indexOf(typesToExcludeArr[i]) >= 0) {
return;
}
}
// let toExcludeArr
// console.log('TODO!!!');
// todo
// return (getNodeText(sourceFile, declaration).indexOf(typeName) >= 0);
}
result.push(getMassagedTopLevelDeclarationText(sourceFile, declaration));
......
......@@ -13,16 +13,25 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import {Position} from 'vs/editor/common/core/position';
import {Range} from 'vs/editor/common/core/range';
/**
* @internal
*/
export interface IContentWidgetData {
widget: IContentWidget;
position: IContentWidgetPosition;
}
/**
* @internal
*/
export interface IOverlayWidgetData {
widget: IOverlayWidget;
position: IOverlayWidgetPosition;
}
/**
* @internal
*/
export interface ICodeEditorHelper {
getScrollWidth(): number;
getScrollLeft(): number;
......@@ -37,6 +46,9 @@ export interface ICodeEditorHelper {
getOffsetForColumn(lineNumber:number, column:number): number;
}
/**
* @internal
*/
export interface IView extends IDisposable {
domNode: HTMLElement;
......@@ -69,6 +81,9 @@ export interface IView extends IDisposable {
removeOverlayWidget(widgetData: IOverlayWidgetData): void;
}
/**
* @internal
*/
export interface IViewZoneData {
viewZoneId: number;
positionBefore:Position;
......@@ -77,6 +92,9 @@ export interface IViewZoneData {
afterLineNumber: number;
}
/**
* @internal
*/
export interface IMouseDispatchData {
position: Position;
/**
......@@ -93,6 +111,9 @@ export interface IMouseDispatchData {
shiftKey: boolean;
}
/**
* @internal
*/
export interface IViewController {
dispatchMouse(data:IMouseDispatchData);
......@@ -112,6 +133,9 @@ export interface IViewController {
emitMouseDown(e:IEditorMouseEvent): void;
}
/**
* @internal
*/
export var ClassNames = {
TEXTAREA_COVER: 'textAreaCover',
TEXTAREA: 'inputarea',
......@@ -131,6 +155,9 @@ export var ClassNames = {
VIEW_ZONES: 'view-zones'
};
/**
* @internal
*/
export interface IViewportInfo {
visibleRange: Range;
width:number;
......@@ -347,10 +374,14 @@ export interface IEditorMouseEvent {
target: IMouseTarget;
}
/**
* @internal
*/
export type ISimpleEditorContributionCtor = IConstructorSignature1<ICodeEditor, editorCommon.IEditorContribution>;
/**
* An editor contribution descriptor that will be used to construct editor contributions
* @internal
*/
export interface IEditorContributionDescriptor {
/**
......@@ -362,6 +393,7 @@ export interface IEditorContributionDescriptor {
/**
* An overview ruler
* @internal
*/
export interface IOverviewRuler {
getDomNode(): HTMLElement;
......@@ -429,6 +461,7 @@ export interface ICodeEditor extends editorCommon.ICommonCodeEditor {
/**
* Get the view zones.
* @internal
*/
getWhitespaces(): editorCommon.IEditorWhitespace[];
......@@ -465,9 +498,13 @@ export interface ICodeEditor extends editorCommon.ICommonCodeEditor {
/**
* Set the model ranges that will be hidden in the view.
* @internal
*/
setHiddenAreas(ranges:editorCommon.IRange[]): void;
/**
* @internal
*/
setAriaActiveDescendant(id:string): void;
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册