mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 09:08:48 +01:00
Reduce standalone editor API through @internal markers
This commit is contained in:
Vendored
+30
-908
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,5 @@
|
||||
// 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;
|
||||
}
|
||||
#include(vs/base/common/winjs.base.d.ts): TValueCallback, ProgressCallback, TPromise
|
||||
|
||||
export class Emitter<T> {
|
||||
constructor();
|
||||
event: IEvent<T>;
|
||||
fire(event?: T): void;
|
||||
dispose(): void;
|
||||
}
|
||||
#include(vs/base/common/uri): URI
|
||||
|
||||
#include(vs/base/common/winjs.base.d.ts): TValueCallback, ProgressCallback, TPromise
|
||||
// TODO@Alex: START remove this
|
||||
#include(vs/base/common/eventEmitter): EmitterEvent, ListenerCallback, BulkListenerCallback, IEventEmitter
|
||||
// TODO@Alex: END remove this
|
||||
|
||||
#include(vs/base/common/uri): URI
|
||||
#include(vs/base/common/keyCodes): KeyCode, KeyMod
|
||||
|
||||
#include(vs/base/common/eventEmitter): EmitterEvent, ListenerCallback, BulkListenerCallback, IEventEmitter
|
||||
#include(vs/base/common/htmlContent): IHTMLContentElementCode, IHTMLContentElement
|
||||
|
||||
#include(vs/base/common/keyCodes): KeyCode, KeyMod
|
||||
#include(vs/base/common/actions): IAction
|
||||
|
||||
#include(vs/base/common/htmlContent): IHTMLContentElementCode, IHTMLContentElement
|
||||
#include(vs/base/browser/keyboardEvent): IKeyboardEvent
|
||||
#include(vs/base/browser/mouseEvent): IMouseEvent
|
||||
#include(vs/editor/common/editorCommon): IScrollEvent
|
||||
|
||||
#include(vs/base/common/actions): IAction
|
||||
|
||||
#include(vs/base/browser/keyboardEvent): IKeyboardEvent
|
||||
|
||||
#include(vs/base/browser/mouseEvent): IMouseEvent
|
||||
|
||||
export interface IPlatformServices {
|
||||
}
|
||||
|
||||
export interface IInstantiationService {
|
||||
}
|
||||
|
||||
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/base/browser/ui/scrollbar/scrollableElementOptions): ScrollbarVisibility
|
||||
|
||||
#include(vs/editor/common/core/viewLineToken): ViewLineToken
|
||||
#includeAll(vs/editor/common/editorCommon): IPosition, IRange, ISelection, SelectionDirection, IScrollEvent
|
||||
|
||||
#includeAll(vs/editor/common/editorCommon): IPosition, IRange, SelectionDirection, ISelection, IFoundBracket
|
||||
|
||||
#includeAll(vs/editor/browser/editorBrowser):
|
||||
#includeAll(vs/editor/browser/editorBrowser):
|
||||
|
||||
}
|
||||
+63
-14
@@ -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));
|
||||
});
|
||||
|
||||
+70
-17
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user