@@ -58,6 +58,12 @@ function initLanguages(monaco: Monaco): void {
58
58
for ( const extension of extensions || [ ] ) {
59
59
languagesByExt [ extension ] = id ;
60
60
}
61
+ if ( id === 'typescript' ) {
62
+ monaco . languages . typescript . typescriptDefaults . setCompilerOptions ( {
63
+ // this is needed to suppress error annotations in tsx regarding missing --jsx flag.
64
+ jsx : monaco . languages . typescript . JsxEmit . Preserve ,
65
+ } ) ;
66
+ }
61
67
}
62
68
}
63
69
@@ -72,6 +78,8 @@ function updateEditor(monaco: Monaco, editor: IStandaloneCodeEditor, filename: s
72
78
const language = model . getLanguageId ( ) ;
73
79
const newLanguage = getLanguage ( filename ) ;
74
80
if ( language !== newLanguage ) monaco . editor . setModelLanguage ( model , newLanguage ) ;
81
+ // TODO: Need to update the model uri with the new filename, but there is no easy way currently, see
82
+ // https://github.com/microsoft/monaco-editor/discussions/3751
75
83
}
76
84
77
85
// export editor for customization - https://github.com/go-gitea/gitea/issues/10409
@@ -135,19 +143,18 @@ export async function createMonaco(textarea: HTMLTextAreaElement, filename: stri
135
143
} ) ;
136
144
updateTheme ( monaco ) ;
137
145
146
+ const model = monaco . editor . createModel ( textarea . value , language , monaco . Uri . file ( filename ) ) ;
147
+
138
148
const editor = monaco . editor . create ( container , {
139
- value : textarea . value ,
149
+ model ,
140
150
theme : 'gitea' ,
141
- language,
142
151
...other ,
143
152
} ) ;
144
153
145
154
monaco . editor . addKeybindingRules ( [
146
155
{ keybinding : monaco . KeyCode . Enter , command : null } , // disable enter from accepting code completion
147
156
] ) ;
148
157
149
- const model = editor . getModel ( ) ;
150
- if ( ! model ) throw new Error ( 'Unable to get editor model' ) ;
151
158
model . onDidChangeContent ( ( ) => {
152
159
textarea . value = editor . getValue ( {
153
160
preserveBOM : true ,
0 commit comments