Skip to content

Commit 06f0ff5

Browse files
stonedJJ
authored andcommitted
Fix code highlighting using the correct scope name
... when using a recent version of Raku/atom-language-perl6 Recently the scope name for Raku code has changed from 'source.perl6fe' to 'source.raku' in the package atom-language-perl6. See Raku/atom-language#96 We try to detect this change by testing for the presence of grammar file 'raku.cson', which beforehand was named 'perl6fe.cson'
1 parent 87e5ad6 commit 06f0ff5

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

highlights/highlight-file.coffee

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@ Highlights = require 'highlights'
44
fs = require 'fs'
55
path = require 'path'
66
highlighter = new Highlights()
7+
modPath = require.resolve('./atom-language-perl6/package.json')
78
highlighter.requireGrammarsSync
8-
modulePath: require.resolve('./atom-language-perl6/package.json')
9+
modulePath: modPath
10+
11+
rakuGrammarPath = path.join(path.dirname(modPath), 'grammars', 'raku.cson')
12+
if fs.existsSync(rakuGrammarPath)
13+
rakuScopeName = 'source.raku'
14+
else
15+
rakuScopeName = 'source.perl6fe'
916

1017
file_to_hl = path.resolve(process.argv[2])
1118
foo = ->
1219
fs.readFileSync file_to_hl, 'utf8'
1320

1421
html = highlighter.highlightSync
1522
fileContents: foo()
16-
scopeName: 'source.perl6fe'
23+
scopeName: rakuScopeName
1724

1825
console.log html

highlights/highlight-filename-from-stdin.coffee

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ Highlights = require 'highlights'
44
fs = require 'fs'
55
path = require 'path'
66
highlighter = new Highlights()
7+
modPath = require.resolve('./atom-language-perl6/package.json')
78
highlighter.requireGrammarsSync
8-
modulePath: require.resolve('./atom-language-perl6/package.json')
9+
modulePath: modPath
10+
11+
rakuGrammarPath = path.join(path.dirname(modPath), 'grammars', 'raku.cson')
12+
if fs.existsSync(rakuGrammarPath)
13+
rakuScopeName = 'source.raku'
14+
else
15+
rakuScopeName = 'source.perl6fe'
916

1017
stdin = process.openStdin()
1118
stdin.setEncoding 'utf8'
@@ -27,7 +34,7 @@ process_file = (given_path) ->
2734
if read_err
2835
console.error read_err
2936
else
30-
highlighter.highlight (fileContents: file_str, scopeName: 'source.perl6fe'), (hl_err, html) ->
37+
highlighter.highlight (fileContents: file_str, scopeName: rakuScopeName), (hl_err, html) ->
3138
if hl_err
3239
console.error hl_err
3340
else

highlights/highlight-folder.coffee

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@ Highlights = require 'highlights'
22
fs = require 'fs'
33
path = require 'path'
44
highlighter = new Highlights()
5+
modPath = require.resolve('./atom-language-perl6/package.json')
56
highlighter.requireGrammarsSync
6-
modulePath: require.resolve('./atom-language-perl6/package.json')
7+
modulePath: modPath)
8+
9+
rakuGrammarPath = path.join(path.dirname(modPath), 'grammars', 'raku.cson')
10+
if fs.existsSync(rakuGrammarPath)
11+
rakuScopeName = 'source.raku'
12+
else
13+
rakuScopeName = 'source.perl6fe'
714

815
TestFolder = path.resolve('TestFolder')
916
files = fs.readdirSync(TestFolder)
@@ -13,6 +20,6 @@ for file in files
1320
fs.readFileSync path.resolve(TestFolder, file), 'utf8'
1421
html = highlighter.highlightSync
1522
fileContents: foo()
16-
scopeName: 'source.perl6fe'
23+
scopeName: rakuScopeName
1724

1825
console.log html

0 commit comments

Comments
 (0)