forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.ts
More file actions
152 lines (133 loc) · 6.4 KB
/
Copy pathjavascript.ts
File metadata and controls
152 lines (133 loc) · 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import winjs = require('vs/base/common/winjs.base');
import tokenization = require('vs/languages/typescript/common/features/tokenization');
import javascriptWorker = require('vs/languages/javascript/common/javascriptWorker');
import typescriptMode = require('vs/languages/typescript/common/typescriptMode');
import typescript = require('vs/languages/typescript/common/typescript');
import EditorCommon = require('vs/editor/common/editorCommon');
import Modes = require('vs/editor/common/modes');
import supports = require('vs/editor/common/modes/supports');
import extensions = require('vs/languages/javascript/common/javascript.extensions');
import {createWordRegExp} from 'vs/editor/common/modes/abstractMode';
import {AsyncDescriptor, AsyncDescriptor2, createAsyncDescriptor2} from 'vs/platform/instantiation/common/descriptors';
import {OnEnterSupport} from 'vs/editor/common/modes/supports/onEnter';
import {IThreadService} from 'vs/platform/thread/common/thread';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
export class JSMode extends typescriptMode.TypeScriptMode<javascriptWorker.JavaScriptWorker> {
public outlineSupport: Modes.IOutlineSupport;
public declarationSupport: Modes.IDeclarationSupport;
public referenceSupport: Modes.IReferenceSupport;
public extraInfoSupport: Modes.IExtraInfoSupport;
public logicalSelectionSupport: Modes.ILogicalSelectionSupport;
public typeDeclarationSupport: Modes.ITypeDeclarationSupport;
public suggestSupport: Modes.ISuggestSupport;
public onEnterSupport: Modes.IOnEnterSupport;
constructor(
descriptor:Modes.IModeDescriptor,
@IInstantiationService instantiationService: IInstantiationService,
@IThreadService threadService: IThreadService,
@ITelemetryService telemetryService: ITelemetryService
) {
super(descriptor, instantiationService, threadService, telemetryService);
this.tokenizationSupport = tokenization.createTokenizationSupport(this, tokenization.Language.EcmaScript5);
this.referenceSupport = new supports.ReferenceSupport(this, {
tokens: [],
findReferences: (resource, position, includeDeclaration) => this.findReferences(resource, position, includeDeclaration)});
this.declarationSupport = new supports.DeclarationSupport(this, {
tokens: [],
findDeclaration: (resource, position) => this.findDeclaration(resource, position)});
this.parameterHintsSupport = new supports.ParameterHintsSupport(this, {
triggerCharacters: ['(', ','],
excludeTokens: ['string.js', 'string.escape.js'],
getParameterHints: (resource, position) => this.getParameterHints(resource, position)});
this.electricCharacterSupport = new supports.BracketElectricCharacterSupport(this,
{
brackets: [
{ tokenType: 'delimiter.bracket.js', open: '{', close: '}', isElectric: true },
{ tokenType: 'delimiter.array.js', open: '[', close: ']', isElectric: true },
{ tokenType: 'delimiter.parenthesis.js', open: '(', close: ')', isElectric: true } ],
docComment: { scope: 'comment.doc', open: '/**', lineStart: ' * ', close: ' */' }
});
this.characterPairSupport = new supports.CharacterPairSupport(this, {
autoClosingPairs:
[ { open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] }
]});
this.onEnterSupport = new OnEnterSupport(this.getId(), {
brackets: [
{ open: '(', close: ')' },
{ open: '{', close: '}' },
{ open: '[', close: ']' }
],
regExpRules: [
{
// e.g. /** | */
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
afterText: /^\s*\*\/$/,
action: { indentAction: Modes.IndentAction.IndentOutdent, appendText: ' * ' }
},
{
// e.g. /** ...|
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
action: { indentAction: Modes.IndentAction.None, appendText: ' * ' }
},
{
// e.g. * ...|
beforeText: /^(\t|(\ \ ))*\ \*\ ([^\*]|\*(?!\/))*$/,
action: { indentAction: Modes.IndentAction.None, appendText: '* ' }
},
{
// e.g. */|
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
action: { indentAction: Modes.IndentAction.None, removeText: 1 }
}
]
});
this.suggestSupport = new supports.SuggestSupport(this, {
triggerCharacters: ['.'],
excludeTokens: ['string', 'comment', 'number', 'numeric'],
sortBy: [{type:'reference', partSeparator: '/'}],
suggest: (resource, position) => this.suggest(resource, position),
getSuggestionDetails: (resource, position, suggestion) => this.getSuggestionDetails(resource, position, suggestion)});
}
public asyncCtor(): winjs.Promise {
if (!this._threadService.isInMainThread) {
return new winjs.Promise((c, e, p) => {
// TODO@Alex: workaround for missing `bundles` config, before instantiating the javascriptWorker, we ensure the typescriptWorker has been loaded
(<any>require)(['vs/languages/typescript/common/typescriptWorker2'], (worker:any) => {
c(this);
});
});
} else {
return winjs.Promise.as(this);
}
}
// ---- specialize by override
protected _getProjectResolver(): AsyncDescriptor<typescript.IProjectResolver2>|typescript.IProjectResolver2 {
return extensions.Extensions.getProjectResolver() || extensions.Defaults.ProjectResolver;
}
_shouldBeValidated(model: EditorCommon.IModel): boolean {
return model.getMode() === this || /\.(d\.ts|js)$/.test(model.getAssociatedResource().fsPath);
}
protected _getWorkerDescriptor(): AsyncDescriptor2<Modes.IMode, Modes.IWorkerParticipant[], javascriptWorker.JavaScriptWorker> {
return createAsyncDescriptor2('vs/languages/javascript/common/javascriptWorker', 'JavaScriptWorker');
}
public getCommentsConfiguration(): Modes.ICommentsConfiguration {
return { lineCommentTokens: ['//'], blockCommentStartToken: '/*', blockCommentEndToken: '*/' };
}
private static JS_WORD_DEFINITION = createWordRegExp('$');
public getWordDefinition(): RegExp {
return JSMode.JS_WORD_DEFINITION;
}
public get filter() {
return void 0;
}
}