Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for language abbreviations #263

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/components/LanguageSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
const items = LANGUAGES.map(l => {
return {
"token": l.token,
"name": l.name
"name": l.name,
"abbreviations": l.abbreviations,
}
}).sort((a, b) => {
return a.name.localeCompare(b.name)
})
items.unshift({token: "auto", name:"Auto-detect"})
items.unshift({token: "auto", name:"Auto-detect", abbreviations: []})

export default {
data() {
Expand All @@ -27,7 +28,9 @@
computed: {
filteredItems() {
return items.filter((lang) => {
return lang.name.toLowerCase().indexOf(this.filter.toLowerCase()) !== -1
// filter by name or abbreviation
return (lang.name.toLowerCase().indexOf(this.filter.toLowerCase()) !== -1)
|| lang.abbreviations.some(abbr => abbr.toLowerCase().indexOf(this.filter.toLowerCase()) !== -1)
})
},
},
Expand Down
37 changes: 36 additions & 1 deletion src/editor/languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ class Language {
* @param parser: The Lezer parser used to parse the language
* @param guesslang: The name of the language as used by the guesslang library
* @param prettier: The prettier configuration for the language (if any)
* @param abbreviations: The abbreviations used to identify the language in the language selector
*/
constructor({ token, name, parser, guesslang, prettier }) {
constructor({ token, name, parser, guesslang, prettier, abbreviations }) {
this.token = token
this.name = name
this.parser = parser
this.guesslang = guesslang
this.prettier = prettier
this.abbreviations = abbreviations
}

get supportsFormat() {
Expand All @@ -64,207 +66,240 @@ export const LANGUAGES = [
name: "Plain Text",
parser: null,
guesslang: null,
abbreviations: ["txt"],
}),
new Language({
token: "math",
name: "Math",
parser: null,
guesslang: null,
abbreviations: [],
}),
new Language({
token: "json",
name: "JSON",
parser: jsonLanguage.parser,
guesslang: "json",
prettier: {parser:"json-stringify", plugins: [babelPrettierPlugin, prettierPluginEstree]},
abbreviations: [],
}),
new Language({
token: "python",
name: "Python",
parser: pythonLanguage.parser,
guesslang: "py",
abbreviations: ["py"],
}),
new Language({
token: "html",
name: "HTML",
parser: htmlLanguage.parser,
guesslang: "html",
prettier: {parser:"html", plugins: [htmlPrettierPlugin]},
abbreviations: [],
}),
new Language({
token: "sql",
name: "SQL",
parser: StandardSQL.language.parser,
guesslang: "sql",
abbreviations: [],
}),
new Language({
token: "markdown",
name: "Markdown",
parser: markdownLanguage.parser,
guesslang: "md",
prettier: {parser:"markdown", plugins: [markdownPrettierPlugin]},
abbreviations: ["md"],
}),
new Language({
token: "java",
name: "Java",
parser: javaLanguage.parser,
guesslang: "java",
abbreviations: [],
}),
new Language({
token: "lezer",
name: "Lezer",
parser: lezerLanguage.parser,
guesslang: null,
abbreviations: [],
}),
new Language({
token: "php",
name: "PHP",
parser: phpLanguage.parser,
guesslang: "php",
abbreviations: [],
}),
new Language({
token: "css",
name: "CSS",
parser: cssLanguage.parser,
guesslang: "css",
prettier: {parser:"css", plugins: [cssPrettierPlugin]},
abbreviations: [],
}),
new Language({
token: "xml",
name: "XML",
parser: xmlLanguage.parser,
guesslang: "xml",
abbreviations: [],
}),
new Language({
token: "cpp",
name: "C++",
parser: cppLanguage.parser,
guesslang: "cpp",
abbreviations: [],
}),
new Language({
token: "rust",
name: "Rust",
parser: rustLanguage.parser,
guesslang: "rs",
abbreviations: ["rs"],
}),
new Language({
token: "csharp",
name: "C#",
parser: csharpLanguage.parser,
guesslang: "cs",
abbreviations: ["cs"],
}),
new Language({
token: "ruby",
name: "Ruby",
parser: StreamLanguage.define(ruby).parser,
guesslang: "rb",
abbreviations: ["rb"],
}),
new Language({
token: "shell",
name: "Shell",
parser: StreamLanguage.define(shell).parser,
guesslang: "sh",
abbreviations: ["sh"],
}),
new Language({
token: "yaml",
name: "YAML",
parser: StreamLanguage.define(yaml).parser,
guesslang: "yaml",
prettier: {parser:"yaml", plugins: [yamlPrettierPlugin]},
abbreviations: ["yml"],
}),
new Language({
token: "toml",
name: "TOML",
parser: StreamLanguage.define(toml).parser,
guesslang: "toml",
abbreviations: [],
}),
new Language({
token: "golang",
name: "Go",
parser: StreamLanguage.define(go).parser,
guesslang: "go",
abbreviations: ["go"],
}),
new Language({
token: "clojure",
name: "Clojure",
parser: StreamLanguage.define(clojure).parser,
guesslang: "clj",
abbreviations: ["clj"],
}),
new Language({
token: "erlang",
name: "Erlang",
parser: StreamLanguage.define(erlang).parser,
guesslang: "erl",
abbreviations: ["erl"],
}),
new Language({
token: "javascript",
name: "JavaScript",
parser: javascriptLanguage.parser,
guesslang: "js",
prettier: {parser:"babel", plugins: [babelPrettierPlugin, prettierPluginEstree]},
abbreviations: ["js"],
}),
new Language({
token: "jsx",
name: "JSX",
parser: jsxLanguage.parser,
guesslang: null,
prettier: {parser:"babel", plugins: [babelPrettierPlugin, prettierPluginEstree]},
abbreviations: [],
}),
new Language({
token: "typescript",
name: "TypeScript",
parser: typescriptLanguage.parser,
guesslang: "ts",
prettier: {parser:"typescript", plugins: [typescriptPlugin, prettierPluginEstree]},
abbreviations: ["ts"],
}),
new Language({
token: "tsx",
name: "TSX",
parser: tsxLanguage.parser,
guesslang: null,
prettier: {parser:"typescript", plugins: [typescriptPlugin, prettierPluginEstree]},
abbreviations: [],
}),
new Language({
token: "swift",
name: "Swift",
parser: StreamLanguage.define(swift).parser,
guesslang: "swift",
abbreviations: [],
}),
new Language({
token: "kotlin",
name: "Kotlin",
parser: StreamLanguage.define(kotlin).parser,
guesslang: "kt",
abbreviations: ["kt"],
}),
new Language({
token: "groovy",
name: "Groovy",
parser: StreamLanguage.define(groovy).parser,
guesslang: "groovy",
abbreviations: [],
}),
new Language({
token: "diff",
name: "Diff",
parser: StreamLanguage.define(diff).parser,
guesslang: null,
abbreviations: [],
}),
new Language({
token: "powershell",
name: "PowerShell",
parser: StreamLanguage.define(powerShell).parser,
guesslang: "ps1",
abbreviations: ["ps1"],
}),
new Language({
token: "vue",
name: "Vue",
parser: vueLanguage.parser,
guesslang: null,
abbreviations: [],
}),
new Language({
token: "dart",
name: "Dart",
parser: StreamLanguage.define(dart).parser,
guesslang: "dart",
abbreviations: [],
}),
]

Expand Down
Loading