Skip to content

Commit dcdc9bb

Browse files
committed
Fixed indentation in src/main/mode.ts.
1 parent 28f6de5 commit dcdc9bb

1 file changed

Lines changed: 129 additions & 129 deletions

File tree

src/main/mode.ts

Lines changed: 129 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -33,74 +33,74 @@ import logger = require('../commons/logger');
3333
import Formatting = TypeScript.Services.Formatting;
3434

3535
class Token {
36-
string: string;
37-
classification: ts.TokenClass;
38-
length: number;
39-
position: number;
36+
string: string;
37+
classification: ts.TokenClass;
38+
length: number;
39+
position: number;
4040
}
4141

4242

4343
class LineDescriptor {
44-
tokenMap: { [position: number]: Token };
45-
eolState: ts.EndOfLineState = ts.EndOfLineState.Start;
44+
tokenMap: { [position: number]: Token };
45+
eolState: ts.EndOfLineState = ts.EndOfLineState.Start;
4646
text: string = '';
4747

48-
clone(): LineDescriptor {
49-
var clone: LineDescriptor = new LineDescriptor();
50-
clone.tokenMap = this.tokenMap;
51-
clone.eolState = this.eolState;
52-
clone.text = this.text;
53-
return clone;
54-
}
48+
clone(): LineDescriptor {
49+
var clone: LineDescriptor = new LineDescriptor();
50+
clone.tokenMap = this.tokenMap;
51+
clone.eolState = this.eolState;
52+
clone.text = this.text;
53+
return clone;
54+
}
5555
}
5656

5757

5858

5959
class TypeScriptMode implements CodeMirror.CodeMirrorMode<LineDescriptor> {
60-
private options: CodeMirror.EditorConfiguration;
60+
private options: CodeMirror.EditorConfiguration;
6161

62-
lineComment = '//';
63-
blockCommentStart = '/*';
64-
blockCommentEnd = '*/';
65-
electricChars = ':{}[]()';
62+
lineComment = '//';
63+
blockCommentStart = '/*';
64+
blockCommentEnd = '*/';
65+
electricChars = ':{}[]()';
6666

67-
constructor(options: CodeMirror.EditorConfiguration) {
68-
this.options = options;
69-
}
67+
constructor(options: CodeMirror.EditorConfiguration) {
68+
this.options = options;
69+
}
7070

71-
startState() {
72-
return new LineDescriptor();
73-
}
71+
startState() {
72+
return new LineDescriptor();
73+
}
7474

75-
copyState(lineDescriptor: LineDescriptor) {
76-
return lineDescriptor.clone();
77-
}
75+
copyState(lineDescriptor: LineDescriptor) {
76+
return lineDescriptor.clone();
77+
}
7878

79-
token(stream: CodeMirror.CodeMirrorStream, lineDescriptor: LineDescriptor) {
80-
if (stream.sol()) {
81-
this.initializeLineDescriptor(lineDescriptor, stream.string);
82-
}
83-
84-
var token = lineDescriptor.tokenMap[stream.pos];
85-
if (token) {
86-
var textBefore: string = stream.string.substr(0, stream.pos);
87-
for (var i = 0; i < token.length; i++) {
88-
stream.next();
89-
}
90-
return getStyleForToken(token, textBefore);
91-
} else {
92-
stream.skipToEnd();
93-
}
94-
95-
return null;
96-
}
97-
98-
99-
indent(lineDescriptor: LineDescriptor , textAfter: string): number {
100-
if (lineDescriptor.eolState !== ts.EndOfLineState.Start) {
79+
token(stream: CodeMirror.CodeMirrorStream, lineDescriptor: LineDescriptor) {
80+
if (stream.sol()) {
81+
this.initializeLineDescriptor(lineDescriptor, stream.string);
82+
}
83+
84+
var token = lineDescriptor.tokenMap[stream.pos];
85+
if (token) {
86+
var textBefore: string = stream.string.substr(0, stream.pos);
87+
for (var i = 0; i < token.length; i++) {
88+
stream.next();
89+
}
90+
return getStyleForToken(token, textBefore);
91+
} else {
92+
stream.skipToEnd();
93+
}
94+
95+
return null;
96+
}
97+
98+
99+
indent(lineDescriptor: LineDescriptor , textAfter: string): number {
100+
if (lineDescriptor.eolState !== ts.EndOfLineState.Start) {
101101
//strange bug preven CodeMirror.Pass
102102
return <number>(<any>CodeMirror).Pass;
103-
}
103+
}
104104
var text = lineDescriptor.text + '\n' + (textAfter || 'fakeIdent'),
105105
position = textAfter ? text.length : text.length - 9,
106106
syntaxTree = this.getSyntaxTree(text),
@@ -118,26 +118,26 @@ class TypeScriptMode implements CodeMirror.CodeMirrorMode<LineDescriptor> {
118118
return <number>(<any>CodeMirror).Pass;
119119
}
120120
return indent;
121-
}
121+
}
122122

123123

124-
private initializeLineDescriptor(lineDescriptor: LineDescriptor, text: string) {
125-
var classificationResult = getClassificationsForLine(text, lineDescriptor.eolState),
126-
tokens = classificationResult.tokens;
124+
private initializeLineDescriptor(lineDescriptor: LineDescriptor, text: string) {
125+
var classificationResult = getClassificationsForLine(text, lineDescriptor.eolState),
126+
tokens = classificationResult.tokens;
127127

128128
if (lineDescriptor.text) {
129129
lineDescriptor.text += '\n';
130130
}
131131
lineDescriptor.text += text;
132132
lineDescriptor.eolState = classificationResult.eolState;
133-
lineDescriptor.tokenMap = {};
133+
lineDescriptor.tokenMap = {};
134134

135-
for (var i = 0, l = tokens.length; i < l; i++) {
136-
lineDescriptor.tokenMap[tokens[i].position] = tokens[i];
137-
}
135+
for (var i = 0, l = tokens.length; i < l; i++) {
136+
lineDescriptor.tokenMap[tokens[i].position] = tokens[i];
137+
}
138138

139139

140-
}
140+
}
141141

142142
private getSyntaxTree(text: string) {
143143
return TypeScript.Parser.parse(
@@ -154,82 +154,82 @@ class TypeScriptMode implements CodeMirror.CodeMirrorMode<LineDescriptor> {
154154
var classifier: ts.Classifier = ts.createClassifier(new logger.LogingClass());
155155

156156
function getClassificationsForLine(text: string, eolState: ts.EndOfLineState ) {
157-
var classificationResult = classifier.getClassificationsForLine(text, eolState),
158-
currentPosition = 0,
159-
tokens: Token[] = [];
160-
161-
for (var i = 0, l = classificationResult.entries.length; i < l ; i++) {
162-
var entry = classificationResult.entries[i];
163-
var token = {
164-
string: text.substr(currentPosition, entry.length),
165-
length: entry.length,
166-
classification: entry.classification,
167-
position: currentPosition
168-
};
169-
tokens.push(token);
170-
currentPosition += entry.length;
171-
}
172-
173-
return {
174-
tokens: tokens,
175-
eolState: classificationResult.finalLexState
176-
};
157+
var classificationResult = classifier.getClassificationsForLine(text, eolState),
158+
currentPosition = 0,
159+
tokens: Token[] = [];
160+
161+
for (var i = 0, l = classificationResult.entries.length; i < l ; i++) {
162+
var entry = classificationResult.entries[i];
163+
var token = {
164+
string: text.substr(currentPosition, entry.length),
165+
length: entry.length,
166+
classification: entry.classification,
167+
position: currentPosition
168+
};
169+
tokens.push(token);
170+
currentPosition += entry.length;
171+
}
172+
173+
return {
174+
tokens: tokens,
175+
eolState: classificationResult.finalLexState
176+
};
177177
}
178178

179179
function getStyleForToken(token: Token, textBefore: string): string {
180-
var TokenClass = ts.TokenClass;
181-
switch (token.classification) {
182-
case TokenClass.NumberLiteral:
183-
return 'number';
184-
case TokenClass.StringLiteral:
185-
return 'string';
186-
case TokenClass.RegExpLiteral:
187-
return 'string-2';
188-
case TokenClass.Operator:
189-
return 'operator';
190-
case TokenClass.Comment:
191-
return 'comment';
192-
case TokenClass.Keyword:
193-
switch (token.string) {
194-
case 'string':
195-
case 'number':
196-
case 'void':
197-
case 'bool':
198-
case 'boolean':
199-
return 'variable-2';
200-
case 'static':
201-
case 'public':
202-
case 'private':
203-
case 'export':
204-
case 'get':
205-
case 'set':
206-
return 'qualifier';
207-
case 'class':
208-
case 'function':
209-
case 'module':
210-
case 'var':
211-
return 'def';
212-
default:
213-
return 'keyword';
214-
}
215-
216-
case TokenClass.Identifier:
217-
// Show types (indentifiers in PascalCase) as variable-2, other types (camelCase) as variable
218-
if (token.string.charAt(0).toLowerCase() !== token.string.charAt(0)) {
219-
return 'variable-2';
220-
} else {
221-
return 'variable';
222-
}
223-
case TokenClass.Punctuation:
224-
return 'bracket';
225-
case TokenClass.Whitespace:
226-
default:
227-
return null;
228-
}
180+
var TokenClass = ts.TokenClass;
181+
switch (token.classification) {
182+
case TokenClass.NumberLiteral:
183+
return 'number';
184+
case TokenClass.StringLiteral:
185+
return 'string';
186+
case TokenClass.RegExpLiteral:
187+
return 'string-2';
188+
case TokenClass.Operator:
189+
return 'operator';
190+
case TokenClass.Comment:
191+
return 'comment';
192+
case TokenClass.Keyword:
193+
switch (token.string) {
194+
case 'string':
195+
case 'number':
196+
case 'void':
197+
case 'bool':
198+
case 'boolean':
199+
return 'variable-2';
200+
case 'static':
201+
case 'public':
202+
case 'private':
203+
case 'export':
204+
case 'get':
205+
case 'set':
206+
return 'qualifier';
207+
case 'class':
208+
case 'function':
209+
case 'module':
210+
case 'var':
211+
return 'def';
212+
default:
213+
return 'keyword';
214+
}
215+
216+
case TokenClass.Identifier:
217+
// Show types (indentifiers in PascalCase) as variable-2, other types (camelCase) as variable
218+
if (token.string.charAt(0).toLowerCase() !== token.string.charAt(0)) {
219+
return 'variable-2';
220+
} else {
221+
return 'variable';
222+
}
223+
case TokenClass.Punctuation:
224+
return 'bracket';
225+
case TokenClass.Whitespace:
226+
default:
227+
return null;
228+
}
229229
}
230230

231231
function typeScriptModeFactory(options: CodeMirror.EditorConfiguration, spec: any): CodeMirror.CodeMirrorMode<any> {
232-
return new TypeScriptMode(options);
232+
return new TypeScriptMode(options);
233233
}
234234

235235
export = typeScriptModeFactory;

0 commit comments

Comments
 (0)