Add plain text language to monaco.
This commit is contained in:
@@ -200,15 +200,15 @@ const HooksEditor = () => {
|
|||||||
defaultValue={file?.content}
|
defaultValue={file?.content}
|
||||||
// onChange={val => (state.files[snap.active].content = val)} // Auto save?
|
// onChange={val => (state.files[snap.active].content = val)} // Auto save?
|
||||||
beforeMount={monaco => {
|
beforeMount={monaco => {
|
||||||
if (!snap.editorCtx) {
|
// if (!snap.editorCtx) {
|
||||||
snap.files.forEach(file =>
|
// snap.files.forEach(file =>
|
||||||
monaco.editor.createModel(
|
// monaco.editor.createModel(
|
||||||
file.content,
|
// file.content,
|
||||||
file.language,
|
// file.language,
|
||||||
monaco.Uri.parse(`file:///work/c/${file.name}`)
|
// monaco.Uri.parse(`file:///work/c/${file.name}`)
|
||||||
)
|
// )
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
|
|
||||||
// create the web socket
|
// create the web socket
|
||||||
if (!subscriptionRef.current) {
|
if (!subscriptionRef.current) {
|
||||||
@@ -218,6 +218,11 @@ const HooksEditor = () => {
|
|||||||
aliases: ['C', 'c', 'H', 'h'],
|
aliases: ['C', 'c', 'H', 'h'],
|
||||||
mimetypes: ['text/plain']
|
mimetypes: ['text/plain']
|
||||||
})
|
})
|
||||||
|
monaco.languages.register({
|
||||||
|
id: 'text',
|
||||||
|
extensions: ['.txt'],
|
||||||
|
mimetypes: ['text/plain'],
|
||||||
|
})
|
||||||
MonacoServices.install(monaco)
|
MonacoServices.install(monaco)
|
||||||
const webSocket = createWebSocket(
|
const webSocket = createWebSocket(
|
||||||
process.env.NEXT_PUBLIC_LANGUAGE_SERVER_API_ENDPOINT || ''
|
process.env.NEXT_PUBLIC_LANGUAGE_SERVER_API_ENDPOINT || ''
|
||||||
|
|||||||
@@ -6,13 +6,14 @@ const languageMapping: Record<string, string | undefined> = {
|
|||||||
js: 'javascript',
|
js: 'javascript',
|
||||||
md: 'markdown',
|
md: 'markdown',
|
||||||
c: 'c',
|
c: 'c',
|
||||||
h: 'c'
|
h: 'c',
|
||||||
|
txt: 'text'
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createNewFile = (name: string) => {
|
export const createNewFile = (name: string) => {
|
||||||
const ext = getFileExtention(name) || ''
|
const ext = getFileExtention(name) || ''
|
||||||
|
|
||||||
const emptyFile: IFile = { name, language: languageMapping[ext] || '', content: '' }
|
const emptyFile: IFile = { name, language: languageMapping[ext] || 'text', content: '' }
|
||||||
state.files.push(emptyFile)
|
state.files.push(emptyFile)
|
||||||
state.active = state.files.length - 1
|
state.active = state.files.length - 1
|
||||||
}
|
}
|
||||||
@@ -22,7 +23,7 @@ export const renameFile = (oldName: string, nwName: string) => {
|
|||||||
if (!file) throw Error(`No file exists with name ${oldName}`)
|
if (!file) throw Error(`No file exists with name ${oldName}`)
|
||||||
|
|
||||||
const ext = getFileExtention(nwName) || ''
|
const ext = getFileExtention(nwName) || ''
|
||||||
const language = languageMapping[ext] || ''
|
const language = languageMapping[ext] || 'text'
|
||||||
file.name = nwName
|
file.name = nwName
|
||||||
file.language = language
|
file.language = language
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user