-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
LanguageIds.ts
208 lines (198 loc) · 7.31 KB
/
LanguageIds.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/**
* The data for this file was constructed from:
* ```
* cd ~/projects/clones/vscode/extensions
* find . -type f -iname package.json -exec pcregrep -M '(?:"id":.*)|(?:"extensions":[^\]]+)' {} \; > ~/projects/cspell/src/languageIds.txt`
* ```
*/
import { genSequence } from 'gensequence';
// cspell:ignore cljs cljx cson iname pcregrep fsscript gradle shtml xhtml mdoc aspx jshtm gitconfig bowerrc
// cspell:ignore jshintrc jscsrc eslintrc babelrc webmanifest mdown markdn psgi phtml pssc psrc gypi rhistory
// cspell:ignore rprofile cshtml gemspec cginc ebuild zshrc zprofile zlogin zlogout zshenv dsql ascx axml
// cspell:ignore bpmn csproj dita ditamap dtml fsproj fxml isml mxml adoc
export interface LanguageExtensionDefinition {
id: string;
extensions: string[];
}
export type LanguageExtensionDefinitions = LanguageExtensionDefinition[];
export type ExtensionToLanguageIdMap = Map<string, Set<string>>;
export const languageExtensionDefinitions: LanguageExtensionDefinitions = [
{ id: 'ada', extensions: ['.adb', '.ads'] },
{ id: 'apiblueprint', extensions: ['.apib', '.apiblueprint'] },
{ id: 'asciidoc', extensions: ['.adoc', '.asc', '.asciidoc'] },
{ id: 'bat', extensions: ['.bat', '.cmd'] },
{ id: 'clojure', extensions: ['.clj', '.cljs', '.cljx', '.clojure', '.edn'] },
{ id: 'coffeescript', extensions: ['.coffee', '.cson'] },
{ id: 'c', extensions: ['.c'] },
{
id: 'cpp',
extensions: ['.cpp', '.cc', '.cxx', '.hpp', '.hh', '.hxx', '.h', '.mm', '.ino', '.inl'],
},
{ id: 'csharp', extensions: ['.cs'] },
{ id: 'css', extensions: ['.css'] },
{ id: 'diff', extensions: ['.diff', '.patch', '.rej'] },
{ id: 'dockerfile', extensions: ['.dockerfile'] },
{ id: 'elixir', extensions: ['.ex', '.exs'] },
{ id: 'fsharp', extensions: ['.fs', '.fsi', '.fsx', '.fsscript'] },
{ id: 'go', extensions: ['.go'] },
{ id: 'groovy', extensions: ['.groovy', '.gvy', '.gradle'] },
{ id: 'handlebars', extensions: ['.handlebars', '.hbs'] },
{ id: 'haskell', extensions: ['.hs', '.lhs'] },
{
id: 'html',
extensions: ['.html', '.htm', '.shtml', '.xhtml', '.mdoc', '.jsp', '.asp', '.aspx', '.jshtm', '.volt', '.vue'],
},
{ id: 'ini', extensions: ['.ini'] },
{ id: 'properties', extensions: ['.properties', '.gitconfig', '.cfg', '.conf'] },
{ id: 'jade', extensions: ['.jade', '.pug'] },
{ id: 'java', extensions: ['.java', '.jav'] },
{ id: 'javascriptreact', extensions: ['.jsx'] },
{ id: 'javascript', extensions: ['.js', '.mjs', '.es6'] },
{
id: 'json',
extensions: ['.json', '.jsonc', '.bowerrc', '.jshintrc', '.jscsrc', '.eslintrc', '.babelrc', '.webmanifest'],
},
{ id: 'less', extensions: ['.less'] },
{ id: 'literate haskell', extensions: ['.lhs'] },
{ id: 'lua', extensions: ['.lua'] },
{ id: 'makefile', extensions: ['.mk'] },
{ id: 'markdown', extensions: ['.md', '.mdown', '.markdown', '.markdn'] },
{ id: 'mdx', extensions: ['.mdx'] },
{ id: 'objective-c', extensions: ['.m'] },
{ id: 'perl', extensions: ['.pl', '.pm', '.pod', '.t', '.PL', '.psgi'] },
{ id: 'perl6', extensions: ['.p6', '.pl6', '.pm6', '.nqp'] },
{ id: 'php', extensions: ['.php', '.php4', '.php5', '.phtml', '.ctp'] },
{ id: 'plaintext', extensions: ['.txt'] },
{ id: 'powershell', extensions: ['.ps1', '.psm1', '.psd1', '.pssc', '.psrc'] },
{ id: 'python', extensions: ['.py', '.rpy', '.pyw', '.cpy', '.gyp', '.gypi'] },
{ id: 'r', extensions: ['.r', '.rhistory', '.rprofile', '.rt'] },
{ id: 'razor', extensions: ['.cshtml'] },
{ id: 'ruby', extensions: ['.rb', '.rbx', '.rjs', '.gemspec', '.rake', '.ru'] },
{ id: 'rust', extensions: ['.rs'] },
{ id: 'scala', extensions: ['.scala', '.sc'] },
{ id: 'scss', extensions: ['.scss'] },
{ id: 'shaderlab', extensions: ['.shader', '.cginc'] },
{
id: 'shellscript',
extensions: [
'.sh',
'.bash',
'.bashrc',
'.bash_aliases',
'.bash_profile',
'.bash_login',
'.ebuild',
'.install',
'.profile',
'.bash_logout',
'.zsh',
'.zshrc',
'.zprofile',
'.zlogin',
'.zlogout',
'.zshenv',
'.zsh-theme',
],
},
{ id: 'sql', extensions: ['.sql', '.dsql'] },
{ id: 'swift', extensions: ['.swift'] },
{ id: 'toml', extensions: ['.toml'] },
{ id: 'typescript', extensions: ['.ts'] },
{ id: 'typescriptreact', extensions: ['.tsx'] },
{ id: 'vb', extensions: ['.vb', '.brs', '.vbs', '.bas'] },
{
id: 'xml',
extensions: [
'.ascx',
'.atom',
'.axml',
'.bpmn',
'.config',
'.cpt',
'.csl',
'.csproj.user',
'.csproj',
'.dita',
'.ditamap',
'.dtd',
'.dtml',
'.ent',
'.fsproj',
'.fxml',
'.iml',
'.isml',
'.jmx',
'.launch',
'.menu',
'.mod',
'.mxml',
'.nuspec',
'.opml',
'.owl',
'.proj',
'.pt',
'.pubxml.user',
'.pubxml',
'.rdf',
'.rng',
'.rss',
'.shproj',
'.storyboard',
'.svg',
'.targets',
'.tld',
'.tmx',
'.vbproj.user',
'.vbproj',
'.vcxproj.filters',
'.vcxproj',
'.wsdl',
'.wxi',
'.wxl',
'.wxs',
'.xaml',
'.xbl',
'.xib',
'.xlf',
'.xliff',
'.xml',
'.xoml',
'.xpdl',
'.xsd',
'.xul',
],
},
{ id: 'xsl', extensions: ['.xsl', '.xslt'] },
{ id: 'yaml', extensions: ['.eyaml', '.eyml', '.yaml', '.yml'] },
{ id: 'latex', extensions: ['.tex'] },
{ id: 'map', extensions: ['.map'] },
//
// Special file types used to prevent spell checking.
//
{ id: 'image', extensions: ['.jpg', '.png', '.jpeg', '.tiff', '.bmp', '.gif'] },
// cspell:ignore woff
{
id: 'binary',
extensions: ['.gz', '.exe', '.dll', '.lib', '.obj', '.o', '.tff', '.woff', '.woff2', '.eot', '.ico', '.cur'],
},
];
export const languageIds: string[] = languageExtensionDefinitions.map(({ id }) => id);
let mapExtensionToLanguageIds: ExtensionToLanguageIdMap;
export function buildLanguageExtensionMap(defs: LanguageExtensionDefinitions): ExtensionToLanguageIdMap {
return defs.reduce((map, def) => {
def.extensions.forEach((ext) => {
map.set(ext, (map.get(ext) || new Set<string>()).add(def.id));
});
return map;
}, new Map<string, Set<string>>());
}
export function getLanguagesForExt(ext: string): string[] {
if (!mapExtensionToLanguageIds) {
mapExtensionToLanguageIds = buildLanguageExtensionMap(languageExtensionDefinitions);
}
return genSequence([ext, '.' + ext])
.map((ext) => mapExtensionToLanguageIds.get(ext))
.filter((a) => !!a)
.concatMap<string>((a) => a!) // eslint-disable-line @typescript-eslint/no-non-null-assertion
.toArray();
}