@@ -2,27 +2,34 @@ import uniqueId from 'lodash/uniqueId'
22import React from 'react'
33import { render } from 'react-dom'
44import { observe , observable , computed , action , extendObservable , reaction } from 'mobx'
5-
65import mime from 'mime-types'
76import { Services } from 'monaco-languageclient'
87
9- import codeEditorService from './codeEditorService'
108import assignProps from 'utils/assignProps'
119import getTabType from 'utils/getTabType'
1210import is from 'utils/is'
11+ import config from 'config'
1312import TabStore from 'components/Tab/store'
1413import FileStore from 'commons/File/store'
1514import EditorState from 'components/Editor/state'
1615import { createMonacoServices } from 'components/MonacoEditor/Editors/createHelper'
17- import { findLanguageByextensions , findModeByName } from './utils/findLanguage'
16+ import {
17+ findLanguageByextensions ,
18+ findModeByName ,
19+ findLanguageFileName
20+ } from './utils/findLanguage'
21+ import codeEditorService from './codeEditorService'
1822import ConditionWidget from './ConditionWidget'
1923import initialOptions from './monacoDefaultOptions'
2024import config from 'config'
2125import { state as virtualKeyState } from '../VirtualKey'
2226
23- reaction ( ( ) => initialOptions . theme , ( theme ) => {
24- monaco . editor . setTheme ( theme )
25- } )
27+ reaction (
28+ ( ) => initialOptions . theme ,
29+ ( theme ) => {
30+ monaco . editor . setTheme ( theme )
31+ }
32+ )
2633
2734const state = observable ( {
2835 entities : observable . map ( { } ) ,
@@ -31,7 +38,7 @@ const state = observable({
3138 activeMonacoEditor : null ,
3239 editors : new Map ( ) ,
3340 activeEditorListeners : [ ] ,
34- installed : false ,
41+ installed : false
3542} )
3643
3744const typeDetect = ( title , types ) => {
@@ -47,10 +54,9 @@ class EditorInfo {
4754 EditorState . entities . set ( this . id , this )
4855 this . update ( props )
4956 this . uri = this . filePath
50- ? ( this . filePath . startsWith ( 'jdt://' )
51- || this . filePath . startsWith ( 'omnisharp-metadata://' )
52- ? this . filePath
53- : `file://${ config . _ROOT_URI_ } ${ this . filePath } ` )
57+ ? this . filePath . startsWith ( 'jdt://' ) || this . filePath . startsWith ( 'omnisharp-metadata://' )
58+ ? this . filePath
59+ : `file://${ config . _ROOT_URI_ } ${ this . filePath } `
5460 : `inmemory://model/${ this . id } `
5561
5662 if ( ! props . filePath || this . isMonaco ) {
@@ -65,11 +71,14 @@ class EditorInfo {
6571 this . monacoElement . style . height = '100%'
6672
6773 if ( this . filePath ) {
68- this . languageMode = findLanguageByextensions ( this . filePath . split ( '.' ) . pop ( ) ) . id
74+ const fileName = this . filePath . split ( '/' ) . pop ( )
75+ this . languageMode = fileName . includes ( '.' )
76+ ? findLanguageByextensions ( fileName . split ( '.' ) . pop ( ) ) . id
77+ : findLanguageFileName ( fileName ) . id
6978 }
7079 const model =
71- monaco . editor . getModel ( monaco . Uri . parse ( this . uri ) . toString ( ) ) ||
72- monaco . editor . createModel ( this . content || '' , this . languageMode , monaco . Uri . parse ( this . uri ) )
80+ monaco . editor . getModel ( monaco . Uri . parse ( this . uri ) . toString ( ) ) ||
81+ monaco . editor . createModel ( this . content || '' , this . languageMode , monaco . Uri . parse ( this . uri ) )
7382 this . uri = model . uri . _formatted
7483
7584 this . model = model
@@ -88,7 +97,9 @@ class EditorInfo {
8897
8998 if ( ! state . installed ) {
9099 // install Monaco language client services
91- const services = createMonacoServices ( monacoEditor , { rootUri : `file://${ config . _ROOT_URI_ } ` } )
100+ const services = createMonacoServices ( monacoEditor , {
101+ rootUri : `file://${ config . _ROOT_URI_ } `
102+ } )
92103 Services . install ( services )
93104 state . installed = true
94105 }
@@ -110,13 +121,15 @@ class EditorInfo {
110121 }
111122 }
112123
113- this . disposers . push ( observe ( this , 'content' , ( change ) => {
114- const content = change . newValue || ''
115- if ( content !== monacoEditor . getValue ( ) ) {
116- this . startsWithUTF8BOM = this . content . charCodeAt ( 0 ) === 65279
117- monacoEditor . setValue ( content )
118- }
119- } ) )
124+ this . disposers . push (
125+ observe ( this , 'content' , ( change ) => {
126+ const content = change . newValue || ''
127+ if ( content !== monacoEditor . getValue ( ) ) {
128+ this . startsWithUTF8BOM = this . content . charCodeAt ( 0 ) === 65279
129+ monacoEditor . setValue ( content )
130+ }
131+ } )
132+ )
120133
121134 if ( this . content && this . content . length > 0 ) {
122135 this . startsWithUTF8BOM = this . content . charCodeAt ( 0 ) === 65279
@@ -139,10 +152,10 @@ class EditorInfo {
139152 monacoEditor . addAction ( {
140153 id : 'custom-comment' ,
141154 label : 'comment' ,
142- keybindings : [
143- monaco . KeyMod . CtrlCmd | monaco . KeyCode . US_SLASH
144- ] ,
145- run : ( ) => { /* no */ }
155+ keybindings : [ monaco . KeyMod . CtrlCmd | monaco . KeyCode . US_SLASH ] ,
156+ run : ( ) => {
157+ /* no */
158+ }
146159 } )
147160
148161 monacoEditor . onDidChangeCursorPosition ( ( event ) => {
@@ -159,7 +172,7 @@ class EditorInfo {
159172 if ( props . selection ) {
160173 const pos = {
161174 lineNumber : props . selection . startLineNumber ,
162- column : props . selection . startColumn ,
175+ column : props . selection . startColumn
163176 }
164177 setTimeout ( ( ) => {
165178 monacoEditor . setSelection ( props . selection )
@@ -188,7 +201,7 @@ class EditorInfo {
188201 const [ lineNumber , column ] = position . split ( ':' )
189202 const pos = {
190203 lineNumber : Number ( lineNumber ) ,
191- column : Number ( column ) ,
204+ column : Number ( column )
192205 }
193206 this . monacoEditor . setPosition ( pos )
194207 this . monacoEditor . revealPositionInCenter ( pos , 1 )
@@ -235,45 +248,43 @@ class EditorInfo {
235248 }
236249 }
237250
238- setViewZoneForBreakPoint = ( breakpoint ) => {
239- return new Promise ( ( resolve , reject ) => {
240- const { path, line } = breakpoint
241-
242- this . monacoEditor . changeViewZones ( ( changeAccessor ) => {
243- const domNode = document . createElement ( 'div' )
244- const viewZoneId = changeAccessor . addZone ( {
245- afterLineNumber : line ,
246- heightInLines : 2 ,
247- afterColumn : 0 ,
248- domNode,
249- } )
250- const handleCancel = ( ) => {
251- this . monacoEditor . changeViewZones ( ( _changeAccessor ) => {
252- _changeAccessor . removeZone ( viewZoneId )
253- } )
254- }
255- render ( < ConditionWidget onChange = { resolve } onCancel = { handleCancel } breakpoint = { breakpoint } /> , domNode )
251+ setViewZoneForBreakPoint = breakpoint => new Promise ( ( resolve , reject ) => {
252+ const { path, line } = breakpoint
253+
254+ this . monacoEditor . changeViewZones ( ( changeAccessor ) => {
255+ const domNode = document . createElement ( 'div' )
256+ const viewZoneId = changeAccessor . addZone ( {
257+ afterLineNumber : line ,
258+ heightInLines : 2 ,
259+ afterColumn : 0 ,
260+ domNode
256261 } )
262+ const handleCancel = ( ) => {
263+ this . monacoEditor . changeViewZones ( ( _changeAccessor ) => {
264+ _changeAccessor . removeZone ( viewZoneId )
265+ } )
266+ }
267+ render (
268+ < ConditionWidget onChange = { resolve } onCancel = { handleCancel } breakpoint = { breakpoint } /> ,
269+ domNode
270+ )
257271 } )
258- }
272+ } )
259273
260274 setDebuggerBreakPoint = ( params ) => {
261275 const { line, verified } = params
262276 const debuggerBreakPoint = this . debugBreakPoints . get ( line )
263- const newBreakPoint = this . monacoEditor . deltaDecorations (
264- debuggerBreakPoint || [ ] ,
265- [
266- {
267- range : new monaco . Range ( line , 1 , line , 1 ) ,
268- options : {
269- isWholeLine : false ,
270- glyphMarginClassName : verified
271- ? 'monaco-glyphMargin-breakpoint'
272- : 'monaco-glyphMargin-breakpoint-unverified'
273- }
277+ const newBreakPoint = this . monacoEditor . deltaDecorations ( debuggerBreakPoint || [ ] , [
278+ {
279+ range : new monaco . Range ( line , 1 , line , 1 ) ,
280+ options : {
281+ isWholeLine : false ,
282+ glyphMarginClassName : verified
283+ ? 'monaco-glyphMargin-breakpoint'
284+ : 'monaco-glyphMargin-breakpoint-unverified'
274285 }
275- ]
276- )
286+ }
287+ ] )
277288 this . debugBreakPoints . set ( line , newBreakPoint )
278289 }
279290
0 commit comments