@@ -30,6 +30,16 @@ import { GQLLanguage } from "@hoppscotch/codemirror-lang-graphql"
3030import { html } from "@codemirror/legacy-modes/mode/xml"
3131import { shell } from "@codemirror/legacy-modes/mode/shell"
3232import { yaml } from "@codemirror/legacy-modes/mode/yaml"
33+ import { rust } from "@codemirror/legacy-modes/mode/rust"
34+ import { go } from "@codemirror/legacy-modes/mode/go"
35+ import { clojure } from "@codemirror/legacy-modes/mode/clojure"
36+ import { http } from "@codemirror/legacy-modes/mode/http"
37+ import { csharp , java } from "@codemirror/legacy-modes/mode/clike"
38+ import { powerShell } from "@codemirror/legacy-modes/mode/powershell"
39+ import { python } from "@codemirror/legacy-modes/mode/python"
40+ import { r } from "@codemirror/legacy-modes/mode/r"
41+ import { ruby } from "@codemirror/legacy-modes/mode/ruby"
42+ import { swift } from "@codemirror/legacy-modes/mode/swift"
3343import { isJSONContentType } from "@helpers/utils/contenttypes"
3444import { useStreamSubscriber } from "@composables/stream"
3545import { Completer } from "@helpers/editor/completion"
@@ -157,10 +167,45 @@ const hoppLang = (
157167 return language ? new LanguageSupport ( language , exts ) : exts
158168}
159169
170+ /**
171+ * Map of language MIME types to their corresponding language definitions
172+ * where the import name matches the langMime string exactly.
173+ * These are used with `StreamLanguage.define(...)` to register the language.
174+ */
175+ const streamLanguageMap : Record < string , any > = {
176+ rust,
177+ clojure,
178+ csharp,
179+ go,
180+ http,
181+ java,
182+ powershell : powerShell ,
183+ python,
184+ shell,
185+ html,
186+ r,
187+ ruby,
188+ swift,
189+ }
190+
191+ /**
192+ * Returns the appropriate CodeMirror language object based on the provided MIME type.
193+ *
194+ * Handles specific content types like JSON, JavaScript, GraphQL, XML, etc.
195+ * For simpler languages that directly match the import name, uses a lookup map
196+ * to reduce repetition and automatically defines the StreamLanguage.
197+ *
198+ * @param langMime - The MIME type or shorthand language identifier (e.g., "javascript", "go", "python")
199+ * @returns The corresponding CodeMirror Language object
200+ */
160201const getLanguage = ( langMime : string ) : Language | null => {
202+ // Special case for JSON types
161203 if ( isJSONContentType ( langMime ) ) {
162204 return jsoncLanguage
163- } else if ( langMime === "application/javascript" ) {
205+ } else if (
206+ langMime === "application/javascript" ||
207+ langMime === "javascript"
208+ ) {
164209 return javascriptLanguage
165210 } else if ( langMime === "graphql" ) {
166211 return GQLLanguage
@@ -174,7 +219,13 @@ const getLanguage = (langMime: string): Language | null => {
174219 return StreamLanguage . define ( yaml )
175220 }
176221
177- // None matched, so return null
222+ // Handle cases where langMime directly matches the import name
223+ const streamLang = streamLanguageMap [ langMime ]
224+ if ( streamLang ) {
225+ return StreamLanguage . define ( streamLang )
226+ }
227+
228+ // If no match is found, return null
178229 return null
179230}
180231
0 commit comments