mirror of
https://github.com/stablyai/orca.git
synced 2026-09-30 00:03:15 +00:00
fix(editor): highlight Solidity files (#20928)
Map .sol to Monaco's built-in 'sol' language id. The grammar already ships with monaco-editor; only the extension lookup was missing, so .sol fell through to plaintext. Closes #13835 Co-authored-by: Neil <neil@stably.ai>
This commit is contained in:
@@ -112,6 +112,11 @@ describe('detectLanguage', () => {
|
||||
expect(detectLanguage('C:\\theme\\snippets\\CART.LIQUID')).toBe('liquid')
|
||||
})
|
||||
|
||||
it('maps .sol files to the Monaco built-in sol language id, not the solidity alias', () => {
|
||||
expect(detectLanguage('contracts/Vault.sol')).toBe('sol')
|
||||
expect(detectLanguage('C:\\repo\\contracts\\TOKEN.SOL')).toBe('sol')
|
||||
})
|
||||
|
||||
it('maps Salesforce Apex sources to the apex language id (case-insensitive)', () => {
|
||||
expect(detectLanguage('force-app/main/default/classes/AccountService.cls')).toBe('apex')
|
||||
expect(detectLanguage('force-app/main/default/triggers/AccountTrigger.trigger')).toBe('apex')
|
||||
|
||||
@@ -93,6 +93,8 @@ const EXT_TO_LANGUAGE: Record<string, string> = {
|
||||
'.hrl': 'erlang',
|
||||
'.hs': 'haskell',
|
||||
'.clj': 'clojure',
|
||||
// Why: Monaco registers Solidity under the id 'sol'; 'solidity' is only an alias.
|
||||
'.sol': 'sol',
|
||||
'.vue': 'vue',
|
||||
'.svelte': 'svelte',
|
||||
'.astro': 'astro',
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { createRequire } from 'node:module'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { detectLanguage } from './language-detect'
|
||||
|
||||
// Why: Monaco registers Solidity as id 'sol' with 'solidity' only an alias, and
|
||||
// mapping an alias silently renders plaintext. Pin against the installed package
|
||||
// so an upstream id change fails here instead of in the editor.
|
||||
describe('solidity language id', () => {
|
||||
it('matches the id monaco-editor registers for .sol', () => {
|
||||
const require = createRequire(import.meta.url)
|
||||
const source = readFileSync(
|
||||
require.resolve('monaco-editor/esm/vs/basic-languages/solidity/solidity.contribution.js'),
|
||||
'utf8'
|
||||
)
|
||||
const registeredId = /id:\s*["']([^"']+)["']/.exec(source)?.[1]
|
||||
expect(registeredId).toBeDefined()
|
||||
expect(detectLanguage('contracts/Vault.sol')).toBe(registeredId)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user