@@ -2,26 +2,32 @@ 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'
20- import config from 'config'
2124
22- reaction ( ( ) => initialOptions . theme , ( theme ) => {
23- monaco . editor . setTheme ( theme )
24- } )
25+ reaction (
26+ ( ) => initialOptions . theme ,
27+ ( theme ) => {
28+ monaco . editor . setTheme ( theme )
29+ }
30+ )
2531
2632const state = observable ( {
2733 entities : observable . map ( { } ) ,
@@ -30,7 +36,7 @@ const state = observable({
3036 activeMonacoEditor : null ,
3137 editors : new Map ( ) ,
3238 activeEditorListeners : [ ] ,
33- installed : false ,
39+ installed : false
3440} )
3541
3642const typeDetect = ( title , types ) => {
@@ -46,10 +52,9 @@ class EditorInfo {
4652 EditorState . entities . set ( this . id , this )
4753 this . update ( props )
4854 this . uri = this . filePath
49- ? ( this . filePath . startsWith ( 'jdt://' )
50- || this . filePath . startsWith ( 'omnisharp-metadata://' )
51- ? this . filePath
52- : `file://${ config . _ROOT_URI_ } ${ this . filePath } ` )
55+ ? this . filePath . startsWith ( 'jdt://' ) || this . filePath . startsWith ( 'omnisharp-metadata://' )
56+ ? this . filePath
57+ : `file://${ config . _ROOT_URI_ } ${ this . filePath } `
5358 : `inmemory://model/${ this . id } `
5459
5560 if ( ! props . filePath || this . isMonaco ) {
@@ -64,11 +69,14 @@ class EditorInfo {
6469 this . monacoElement . style . height = '100%'
6570
6671 if ( this . filePath ) {
67- this . languageMode = findLanguageByextensions ( this . filePath . split ( '.' ) . pop ( ) ) . id
72+ const fileName = this . filePath . split ( '/' ) . pop ( )
73+ this . languageMode = fileName . includes ( '.' )
74+ ? findLanguageByextensions ( fileName . split ( '.' ) . pop ( ) ) . id
75+ : findLanguageFileName ( fileName ) . id
6876 }
6977 const model =
70- monaco . editor . getModel ( monaco . Uri . parse ( this . uri ) . toString ( ) ) ||
71- monaco . editor . createModel ( this . content || '' , this . languageMode , monaco . Uri . parse ( this . uri ) )
78+ monaco . editor . getModel ( monaco . Uri . parse ( this . uri ) . toString ( ) ) ||
79+ monaco . editor . createModel ( this . content || '' , this . languageMode , monaco . Uri . parse ( this . uri ) )
7280 this . uri = model . uri . _formatted
7381
7482 this . model = model
@@ -87,7 +95,9 @@ class EditorInfo {
8795
8896 if ( ! state . installed ) {
8997 // install Monaco language client services
90- const services = createMonacoServices ( monacoEditor , { rootUri : `file://${ config . _ROOT_URI_ } ` } )
98+ const services = createMonacoServices ( monacoEditor , {
99+ rootUri : `file://${ config . _ROOT_URI_ } `
100+ } )
91101 Services . install ( services )
92102 state . installed = true
93103 }
@@ -108,13 +118,15 @@ class EditorInfo {
108118 }
109119 }
110120
111- this . disposers . push ( observe ( this , 'content' , ( change ) => {
112- const content = change . newValue || ''
113- if ( content !== monacoEditor . getValue ( ) ) {
114- this . startsWithUTF8BOM = this . content . charCodeAt ( 0 ) === 65279
115- monacoEditor . setValue ( content )
116- }
117- } ) )
121+ this . disposers . push (
122+ observe ( this , 'content' , ( change ) => {
123+ const content = change . newValue || ''
124+ if ( content !== monacoEditor . getValue ( ) ) {
125+ this . startsWithUTF8BOM = this . content . charCodeAt ( 0 ) === 65279
126+ monacoEditor . setValue ( content )
127+ }
128+ } )
129+ )
118130
119131 if ( this . content && this . content . length > 0 ) {
120132 this . startsWithUTF8BOM = this . content . charCodeAt ( 0 ) === 65279
@@ -137,10 +149,10 @@ class EditorInfo {
137149 monacoEditor . addAction ( {
138150 id : 'custom-comment' ,
139151 label : 'comment' ,
140- keybindings : [
141- monaco . KeyMod . CtrlCmd | monaco . KeyCode . US_SLASH
142- ] ,
143- run : ( ) => { /* no */ }
152+ keybindings : [ monaco . KeyMod . CtrlCmd | monaco . KeyCode . US_SLASH ] ,
153+ run : ( ) => {
154+ /* no */
155+ }
144156 } )
145157
146158 monacoEditor . onDidChangeCursorPosition ( ( event ) => {
@@ -157,7 +169,7 @@ class EditorInfo {
157169 if ( props . selection ) {
158170 const pos = {
159171 lineNumber : props . selection . startLineNumber ,
160- column : props . selection . startColumn ,
172+ column : props . selection . startColumn
161173 }
162174 setTimeout ( ( ) => {
163175 monacoEditor . setSelection ( props . selection )
@@ -186,7 +198,7 @@ class EditorInfo {
186198 const [ lineNumber , column ] = position . split ( ':' )
187199 const pos = {
188200 lineNumber : Number ( lineNumber ) ,
189- column : Number ( column ) ,
201+ column : Number ( column )
190202 }
191203 this . monacoEditor . setPosition ( pos )
192204 this . monacoEditor . revealPositionInCenter ( pos , 1 )
@@ -233,45 +245,43 @@ class EditorInfo {
233245 }
234246 }
235247
236- setViewZoneForBreakPoint = ( breakpoint ) => {
237- return new Promise ( ( resolve , reject ) => {
238- const { path, line } = breakpoint
239-
240- this . monacoEditor . changeViewZones ( ( changeAccessor ) => {
241- const domNode = document . createElement ( 'div' )
242- const viewZoneId = changeAccessor . addZone ( {
243- afterLineNumber : line ,
244- heightInLines : 2 ,
245- afterColumn : 0 ,
246- domNode,
247- } )
248- const handleCancel = ( ) => {
249- this . monacoEditor . changeViewZones ( ( _changeAccessor ) => {
250- _changeAccessor . removeZone ( viewZoneId )
251- } )
252- }
253- render ( < ConditionWidget onChange = { resolve } onCancel = { handleCancel } breakpoint = { breakpoint } /> , domNode )
248+ setViewZoneForBreakPoint = breakpoint => new Promise ( ( resolve , reject ) => {
249+ const { path, line } = breakpoint
250+
251+ this . monacoEditor . changeViewZones ( ( changeAccessor ) => {
252+ const domNode = document . createElement ( 'div' )
253+ const viewZoneId = changeAccessor . addZone ( {
254+ afterLineNumber : line ,
255+ heightInLines : 2 ,
256+ afterColumn : 0 ,
257+ domNode
254258 } )
259+ const handleCancel = ( ) => {
260+ this . monacoEditor . changeViewZones ( ( _changeAccessor ) => {
261+ _changeAccessor . removeZone ( viewZoneId )
262+ } )
263+ }
264+ render (
265+ < ConditionWidget onChange = { resolve } onCancel = { handleCancel } breakpoint = { breakpoint } /> ,
266+ domNode
267+ )
255268 } )
256- }
269+ } )
257270
258271 setDebuggerBreakPoint = ( params ) => {
259272 const { line, verified } = params
260273 const debuggerBreakPoint = this . debugBreakPoints . get ( line )
261- const newBreakPoint = this . monacoEditor . deltaDecorations (
262- debuggerBreakPoint || [ ] ,
263- [
264- {
265- range : new monaco . Range ( line , 1 , line , 1 ) ,
266- options : {
267- isWholeLine : false ,
268- glyphMarginClassName : verified
269- ? 'monaco-glyphMargin-breakpoint'
270- : 'monaco-glyphMargin-breakpoint-unverified'
271- }
274+ const newBreakPoint = this . monacoEditor . deltaDecorations ( debuggerBreakPoint || [ ] , [
275+ {
276+ range : new monaco . Range ( line , 1 , line , 1 ) ,
277+ options : {
278+ isWholeLine : false ,
279+ glyphMarginClassName : verified
280+ ? 'monaco-glyphMargin-breakpoint'
281+ : 'monaco-glyphMargin-breakpoint-unverified'
272282 }
273- ]
274- )
283+ }
284+ ] )
275285 this . debugBreakPoints . set ( line , newBreakPoint )
276286 }
277287
0 commit comments