fix: [code-1358]: add highlight support for terraform files in gitblame (#987)

This commit is contained in:
Calvin Lee 2024-01-24 22:41:59 +00:00 committed by Harness
parent f39852dc62
commit 0246d1bc48
3 changed files with 23 additions and 1 deletions

View File

@ -23,6 +23,7 @@ import type { ViewUpdate } from '@codemirror/view'
import type { Text } from '@codemirror/state'
import { languages } from '@codemirror/language-data'
import { markdown } from '@codemirror/lang-markdown'
import { java } from '@codemirror/lang-java'
import { EditorView, keymap, placeholder as placeholderExtension } from '@codemirror/view'
import { Compartment, EditorState, Extension } from '@codemirror/state'
import { color } from '@uiw/codemirror-extensions-color'
@ -205,6 +206,25 @@ export const Editor = React.memo(function CodeMirrorReactEditor({
})
}
}, [filename, forMarkdown, view, languageConfig, markdownLanguageSupport])
useEffect(() => {
if (filename) {
let languageSupport
if (
filename.endsWith('.tf') ||
filename.endsWith('.hcl') ||
filename.endsWith('.tfstate') ||
filename.endsWith('.tfvars')
) {
languageSupport = java()
}
// Add other file extensions and their corresponding language modes
if (languageSupport) {
view.current?.dispatch({
effects: languageConfig.reconfigure(languageSupport)
})
}
}
}, [filename, view, languageConfig, markdownLanguageSupport])
const handleUploadCallback = (file: File) => {
if (!inGitBlame) {
setFile(file)

View File

@ -483,6 +483,7 @@ const TextExtensions = [
'alpine',
'tf',
'tfvars',
'tfstate',
'hcl'
]

View File

@ -471,7 +471,8 @@ const EXTENSION_TO_LANG: Record<string, string> = {
tsx: 'typescript',
tf: 'hcl',
tfvars: 'hcl',
workspace: 'python'
workspace: 'python',
tfstate: 'hcl'
}
export const PLAIN_TEXT = 'plaintext'