提交 70aa7ac5 编写于 作者: M Martin Aeschlimann 提交者: GitHub

Merge pull request #9595 from Microsoft/aeschli/languageconfiguration-cleanup

Replace deprecated __ language APIs with language-configuration alternative
......@@ -8,7 +8,7 @@
"id": "bat",
"extensions": [ ".bat", ".cmd"],
"aliases": [ "Batch", "bat" ],
"configuration": "./bat.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "bat",
......
......@@ -8,7 +8,7 @@
"id": "clojure",
"aliases": ["Clojure", "clojure"],
"extensions": [".clj", ".cljs", ".cljx", ".clojure", ".edn"],
"configuration": "./clojure.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "clojure",
......
......@@ -8,7 +8,7 @@
"id": "coffeescript",
"extensions": [ ".coffee", ".cson" ],
"aliases": [ "CoffeeScript", "coffeescript", "coffee" ],
"configuration": "./coffeescript.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "coffeescript",
......
......@@ -8,13 +8,13 @@
"id": "c",
"extensions": [ ".c"],
"aliases": [ "C", "c" ],
"configuration": "./cpp.configuration.json"
"configuration": "./language-configuration.json"
},
{
"id": "cpp",
"extensions": [ ".cpp", ".cc", ".cxx", ".hpp", ".hh", ".hxx", ".h", ".mm", ".ino", ".inl" ],
"aliases": [ "C++", "Cpp", "cpp"],
"configuration": "./cpp.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "c",
......
......@@ -54,58 +54,15 @@ export function activate(context: ExtensionContext) {
context.subscriptions.push(disposable);
languages.setLanguageConfiguration('css', {
wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]*(?=[^,{;]*[,{]))|(([@#.!])?[\w-?]+%?|[@#!.])/g,
comments: {
blockComment: ['/*', '*/']
},
brackets: [['{', '}'], ['[', ']'], ['(', ')']],
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string'] }
]
}
wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]*(?=[^,{;]*[,{]))|(([@#.!])?[\w-?]+%?|[@#!.])/g
});
languages.setLanguageConfiguration('less', {
wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]+(?=[^,{;]*[,{]))|(([@#.!])?[\w-?]+%?|[@#!.])/g,
comments: {
blockComment: ['/*', '*/'],
lineComment: '//'
},
brackets: [['{', '}'], ['[', ']'], ['(', ')'], ['<', '>']],
__characterPairSupport: {
autoClosingPairs: [
{ open: '"', close: '"', notIn: ['string', 'comment'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
{ open: '{', close: '}', notIn: ['string', 'comment'] },
{ open: '[', close: ']', notIn: ['string', 'comment'] },
{ open: '(', close: ')', notIn: ['string', 'comment'] },
{ open: '<', close: '>', notIn: ['string', 'comment'] },
]
}
wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]+(?=[^,{;]*[,{]))|(([@#.!])?[\w-?]+%?|[@#!.])/g
});
languages.setLanguageConfiguration('scss', {
wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]*(?=[^,{;]*[,{]))|(([@$#.!])?[\w-?]+%?|[@#!$.])/g,
comments: {
blockComment: ['/*', '*/'],
lineComment: '//'
},
brackets: [['{', '}'], ['[', ']'], ['(', ')'], ['<', '>']],
__characterPairSupport: {
autoClosingPairs: [
{ open: '"', close: '"', notIn: ['string', 'comment'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
{ open: '{', close: '}', notIn: ['string', 'comment'] },
{ open: '[', close: ']', notIn: ['string', 'comment'] },
{ open: '(', close: ')', notIn: ['string', 'comment'] },
{ open: '<', close: '>', notIn: ['string', 'comment'] },
]
}
wordPattern: /(#?-?\d*\.\d\w*%?)|(::?[\w-]*(?=[^,{;]*[,{]))|(([@$#.!])?[\w-?]+%?|[@#!$.])/g
});
commands.registerCommand('_css.applyCodeAction', applyCodeAction);
......
{
"comments": {
"blockComment": ["/*", "*/"]
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
"autoClosingPairs": [
{ "open": "{", "close": "}", "notIn": ["string", "comment"] },
{ "open": "[", "close": "]", "notIn": ["string", "comment"] },
{ "open": "(", "close": ")", "notIn": ["string", "comment"] },
{ "open": "\"", "close": "\"", "notIn": ["string", "comment"] },
{ "open": "'", "close": "'", "notIn": ["string", "comment"] }
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
]
}
\ No newline at end of file
......@@ -21,7 +21,8 @@
"id": "css",
"aliases": ["CSS", "css"],
"extensions": [".css"],
"mimetypes": ["text/css"]
"mimetypes": ["text/css"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "css",
......
......@@ -9,7 +9,7 @@
"id": "diff",
"aliases": ["Diff", "diff" ],
"extensions": [".patch", ".diff", ".rej"],
"configuration": "./diff.configuration.json"
"configuration": "./language-configuration.json"
}
],
"grammars": [
......
......@@ -9,7 +9,7 @@
"extensions": [ ".dockerfile" ],
"filenames": [ "Dockerfile" ],
"aliases": [ "Dockerfile" ],
"configuration": "./dockerfile.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "dockerfile",
......
......@@ -8,7 +8,7 @@
"id": "fsharp",
"extensions": [ ".fs", ".fsi", ".ml", ".mli", ".fsx", ".fsscript" ],
"aliases": [ "F#", "FSharp", "fsharp" ],
"configuration": "./fsharp.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "fsharp",
......
......@@ -9,13 +9,13 @@
"id": "git-commit",
"aliases": ["Git Commit Message", "git-commit"],
"filenames": ["COMMIT_EDITMSG", "MERGE_MSG"],
"configuration": "./git-commit.configuration.json"
"configuration": "./git-commit.language-configuration.json"
},
{
"id": "git-rebase",
"aliases": ["Git Rebase Message", "git-rebase"],
"filenames": ["git-rebase-todo"],
"configuration": "./git-rebase.configuration.json"
"configuration": "./git-rebase.language-configuration.json"
}
],
"grammars": [
......
......@@ -8,7 +8,7 @@
"id": "go",
"extensions": [ ".go" ],
"aliases": [ "Go" ],
"configuration": "./go.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "go",
......
......@@ -8,7 +8,7 @@
"id": "groovy",
"aliases": ["Groovy", "groovy"],
"extensions": [".groovy", ".gvy", ".gradle"],
"configuration": "./groovy.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "groovy",
......
......@@ -9,7 +9,7 @@
"extensions": [ ".ini", ".properties", ".gitconfig" ],
"filenames": ["config", ".gitattributes", ".gitconfig", "gitconfig", ".editorconfig"],
"aliases": [ "Ini", "ini" ],
"configuration": "./ini.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "ini",
......
......@@ -8,7 +8,7 @@
"id": "jade",
"extensions": [ ".jade", ".pug" ],
"aliases": [ "Jade", "jade" ],
"configuration": "./jade.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "jade",
......
......@@ -8,7 +8,7 @@
"id": "java",
"extensions": [ ".java", ".jav" ],
"aliases": [ "Java", "java" ],
"configuration": "./java.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "java",
......
{
"comments": {
"lineComment": "//",
"blockComment": [ "/*", "*/" ]
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
]
}
\ No newline at end of file
{
"comments": {
"lineComment": "//",
"blockComment": [ "/*", "*/" ]
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
"autoClosingPairs": [
{ "open": "{", "close": "}" },
{ "open": "[", "close": "]" },
{ "open": "(", "close": ")" },
{ "open": "'", "close": "'", "notIn": ["string"] },
{ "open": "\"", "close": "\"", "notIn": ["string", "comment"] },
{ "open": "`", "close": "`", "notIn": ["string", "comment"] },
{ "open": "/**", "close": " */", "notIn": ["string"] }
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["'", "'"],
["\"", "\""],
["`", "`"]
]
}
\ No newline at end of file
......@@ -27,7 +27,7 @@
"extensions": [
".jsx"
],
"configuration": "./javascript.configuration.json"
"configuration": "./language-configuration.json"
},
{
"id": "javascript",
......@@ -46,7 +46,8 @@
"firstLine": "^#!.*\\bnode",
"mimetypes": [
"text/javascript"
]
],
"configuration": "./language-configuration.json"
}
],
"grammars": [
......
......@@ -89,17 +89,7 @@ export function activate(context: ExtensionContext) {
context.subscriptions.push(disposable);
languages.setLanguageConfiguration('json', {
wordPattern: /(-?\d*\.\d\w*)|([^\[\{\]\}\:\"\,\s]+)/g,
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
{ open: '`', close: '`', notIn: ['string', 'comment'] }
]
}
wordPattern: /(-?\d*\.\d\w*)|([^\[\{\]\}\:\"\,\s]+)/g
});
});
}
......
{
"comments": {
"lineComment": "//",
"blockComment": [ "/*", "*/" ]
},
"brackets": [
["{", "}"],
["[", "]"]
]
}
\ No newline at end of file
{
"comments": {
"lineComment": "//",
"blockComment": [ "/*", "*/" ]
},
"brackets": [
["{", "}"],
["[", "]"]
],
"autoClosingPairs": [
{ "open": "{", "close": "}", "notIn": ["string"] },
{ "open": "[", "close": "]", "notIn": ["string"] },
{ "open": "(", "close": ")", "notIn": ["string"] },
{ "open": "'", "close": "'", "notIn": ["string"] },
{ "open": "\"", "close": "\"", "notIn": ["string", "comment"] },
{ "open": "`", "close": "`", "notIn": ["string", "comment"] }
]
}
\ No newline at end of file
......@@ -35,7 +35,7 @@
"application/json",
"application/manifest+json"
],
"configuration": "./json.configuration.json"
"configuration": "./language-configuration.json"
}
],
"grammars": [
......@@ -54,6 +54,10 @@
"fileMatch": "package.json",
"url": "vscode://schemas/vscode-extensions"
},
{
"fileMatch": "*language-configuration.json",
"url": "vscode://schemas/language-configuration"
},
{
"fileMatch": "vscode://defaultsettings/keybindings.json",
"url": "vscode://schemas/keybindings"
......
{
"comments": {
"blockComment": ["/*", "*/"],
"lineComment": "//"
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"],
["<", ">"]
],
"autoClosingPairs": [
{ "open": "{", "close": "}", "notIn": ["string", "comment"] },
{ "open": "[", "close": "]", "notIn": ["string", "comment"] },
{ "open": "(", "close": ")", "notIn": ["string", "comment"] },
{ "open": "\"", "close": "\"", "notIn": ["string", "comment"] },
{ "open": "'", "close": "'", "notIn": ["string", "comment"] }
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"],
["<", ">"]
]
}
\ No newline at end of file
......@@ -8,7 +8,8 @@
"id": "less",
"aliases": ["Less", "less"],
"extensions": [".less"],
"mimetypes": ["text/x-less", "text/less"]
"mimetypes": ["text/x-less", "text/less"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "less",
......
......@@ -8,7 +8,7 @@
"id": "lua",
"extensions": [ ".lua" ],
"aliases": [ "Lua", "lua" ],
"configuration": "./lua.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "lua",
......
......@@ -8,7 +8,7 @@
"id": "makefile",
"aliases": ["Makefile", "makefile"],
"filenames": [ "Makefile", "makefile", "GNUmakefile", "OCamlMakefile" ],
"configuration": "./make.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "makefile",
......
......@@ -31,7 +31,7 @@
".markdown",
".markdn"
],
"configuration": "./markdown.configuration.json"
"configuration": "./language-configuration.json"
}
],
"grammars": [
......
......@@ -8,7 +8,7 @@
"id": "objective-c",
"extensions": [ ".m" ],
"aliases": [ "Objective-C"],
"configuration": "./objective-c.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "objective-c",
......
......@@ -9,13 +9,13 @@
"aliases": ["Perl", "perl"],
"extensions": [".pl", ".pm", ".pod", ".t", ".PL", ".psgi"],
"firstLine": "^#!.*\\bperl\\b",
"configuration": "./perl.configuration.json"
"configuration": "./perl.language-configuration.json"
}, {
"id": "perl6",
"aliases": ["Perl 6", "perl6"],
"extensions": [".p6", ".pl6", ".pm6", ".nqp"],
"firstLine": "(^#!.*\\bperl6\\b)|use\\s+v6",
"configuration": "./perl6.configuration.json"
"configuration": "./perl6.language-configuration.json"
}],
"grammars": [{
"language": "perl",
......
......@@ -7,6 +7,13 @@
["{", "}"],
["[", "]"],
["(", ")"]
],
"autoClosingPairs": [
{ "open": "{", "close": "}", "notIn": ["string"] },
{ "open": "[", "close": "]", "notIn": ["string"] },
{ "open": "(", "close": ")", "notIn": ["string"] },
{ "open": "'", "close": "'", "notIn": ["string"] },
{ "open": "\"", "close": "\"", "notIn": ["string", "comment"] }
]
}
\ No newline at end of file
......@@ -14,7 +14,7 @@
"extensions": [ ".php", ".php4", ".php5", ".phtml", ".ctp" ],
"aliases": [ "PHP", "php" ],
"mimetypes": ["application/x-php"],
"configuration": "./php.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "php",
......
......@@ -26,16 +26,6 @@ export function activate(context: ExtensionContext): any {
// need to set in the extension host as well as the completion provider uses it.
languages.setLanguageConfiguration('php', {
wordPattern: /(-?\d*\.\d\w*)|([^\-\`\~\!\@\#\%\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] }
]
}
wordPattern: /(-?\d*\.\d\w*)|([^\-\`\~\!\@\#\%\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g
});
}
\ No newline at end of file
......@@ -8,7 +8,7 @@
"id": "powershell",
"extensions": [ ".ps1", ".psm1", ".psd1", ".pssc", ".psrc" ],
"aliases": [ "PowerShell", "powershell", "ps", "ps1" ],
"configuration": "./powershell.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "powershell",
......
......@@ -9,7 +9,7 @@
"extensions": [ ".py", ".rpy", ".pyw", ".cpy", ".gyp", ".gypi" ],
"aliases": [ "Python", "py" ],
"firstLine": "^#!/.*\\bpython[0-9.-]*\\b",
"configuration": "./python.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "python",
......
......@@ -8,7 +8,7 @@
"id": "r",
"extensions": [ ".r", ".rhistory", ".rprofile", ".rt" ],
"aliases": [ "R", "r" ],
"configuration": "./r.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "r",
......
......@@ -9,7 +9,7 @@
"extensions": [ ".rb", ".rbx", ".rjs", ".gemspec", ".pp", ".rake", ".ru" ],
"filenames": [ "rakefile", "gemfile", "guardfile" ],
"aliases": [ "Ruby", "rb" ],
"configuration": "./ruby.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "ruby",
......
......@@ -8,7 +8,7 @@
"id": "rust",
"extensions": [".rs"],
"aliases": ["Rust", "rust"],
"configuration": "./rust.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "rust",
......
{
"comments": {
"blockComment": ["/*", "*/"],
"lineComment": "//"
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"],
["<", ">"]
],
"autoClosingPairs": [
{ "open": "{", "close": "}", "notIn": ["string", "comment"] },
{ "open": "[", "close": "]", "notIn": ["string", "comment"] },
{ "open": "(", "close": ")", "notIn": ["string", "comment"] },
{ "open": "\"", "close": "\"", "notIn": ["string", "comment"] },
{ "open": "'", "close": "'", "notIn": ["string", "comment"] }
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"],
["<", ">"]
]
}
\ No newline at end of file
......@@ -8,7 +8,8 @@
"id": "scss",
"aliases": ["Sass", "scss"],
"extensions": [".scss"],
"mimetypes": ["text/x-scss", "text/scss"]
"mimetypes": ["text/x-scss", "text/scss"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "scss",
......
......@@ -8,7 +8,7 @@
"id": "shaderlab",
"extensions": [".shader", ".cginc"],
"aliases": ["ShaderLab", "shaderlab"],
"configuration": "./shaderlab.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "shaderlab",
......
......@@ -10,7 +10,7 @@
"extensions": [".sh", ".bash", ".bashrc", ".bash_profile", ".bash_login", ".ebuild", ".install", ".profile", ".bash_logout", ".zsh", ".zshrc", ".zprofile", ".zlogin", ".zlogout", ".zshenv"],
"filenames": ["PKGBUILD"],
"firstLine": "^#!.*\\b(bash|zsh|sh|tcsh)|^#\\s*-\\*-[^*]*mode:\\s*shell-script[^*]*-\\*-",
"configuration": "./shellscript.configuration.json",
"configuration": "./language-configuration.json",
"mimetypes": ["text/x-shellscript"]
}],
"grammars": [{
......
......@@ -8,7 +8,7 @@
"id": "sql",
"extensions": [ ".sql" ],
"aliases": [ "SQL" ],
"configuration": "./sql.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "sql",
......
......@@ -8,7 +8,7 @@
"id": "swift",
"aliases": ["Swift","swift"],
"extensions": [".swift"],
"configuration": "./swift.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "swift",
......
{
"comments": {
"lineComment": "//",
"blockComment": [ "/*", "*/" ]
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"],
["<", ">"]
],
"autoClosingPairs": [
{ "open": "{", "close": "}" },
{ "open": "[", "close": "]" },
{ "open": "(", "close": ")" },
{ "open": "'", "close": "'", "notIn": ["string"] },
{ "open": "\"", "close": "\"", "notIn": ["string", "comment"] },
{ "open": "`", "close": "`", "notIn": ["string", "comment"] },
{ "open": "/**", "close": " */", "notIn": ["string"] }
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["<", ">"],
["'", "'"],
["\"", "\""],
["`", "`"]
]
}
\ No newline at end of file
......@@ -37,7 +37,8 @@
],
"extensions": [
".ts"
]
],
"configuration": "./language-configuration.json"
},
{
"id": "typescriptreact",
......@@ -47,7 +48,8 @@
],
"extensions": [
".tsx"
]
],
"configuration": "./language-configuration.json"
}
],
"grammars": [
......
......@@ -168,15 +168,6 @@ class LanguageProvider {
increaseIndentPattern: /^.*\{[^}"']*$/
},
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
comments: {
lineComment: '//',
blockComment: ['/*', '*/']
},
brackets: [
['{', '}'],
['[', ']'],
['(', ')'],
],
onEnterRules: [
{
// e.g. /** | */
......@@ -204,22 +195,7 @@ class LanguageProvider {
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
action: { indentAction: IndentAction.None, removeText: 1 }
}
],
__electricCharacterSupport: {
docComment: { scope: 'comment.documentation', open: '/**', lineStart: ' * ', close: ' */' }
},
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
{ open: '`', close: '`', notIn: ['string', 'comment'] }
]
}
]
});
});
}
......
......@@ -8,7 +8,7 @@
"id": "vb",
"extensions": [ ".vb", ".brs", ".vbs", ".bas" ],
"aliases": [ "Visual Basic", "vb" ],
"configuration": "./vb.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "vb",
......
......@@ -64,7 +64,7 @@
],
"firstLine" : "(\\<\\?xml.*)|(\\<svg)|(\\<\\!doctype\\s+svg)",
"aliases": [ "XML", "xml" ],
"configuration": "./xml.configuration.json"
"configuration": "./xml.language-configuration.json"
}, {
"id": "xsl",
"extensions": [
......@@ -72,7 +72,7 @@
".xslt"
],
"aliases": [ "XSL", "xsl" ],
"configuration": "./xsl.configuration.json"
"configuration": "./xsl.language-configuration.json"
}],
"grammars": [{
"language": "xml",
......
......@@ -9,7 +9,7 @@
"aliases": ["YAML", "yaml"],
"extensions": [".eyaml", ".eyml", ".yaml", ".yml"],
"firstLine": "^#cloud-config",
"configuration": "./yaml.configuration.json"
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "yaml",
......
......@@ -879,6 +879,7 @@ export type CharacterPair = [string, string];
export interface IAutoClosingPairConditional extends IAutoClosingPair {
notIn?: string[];
}
/**
......
......@@ -111,10 +111,7 @@ export class RichEditSupport {
this._handleComments(modeId, this._conf);
this.characterPair = new CharacterPairSupport(LanguageConfigurationRegistry, modeId, this._conf);
if (this._conf.__electricCharacterSupport || this._conf.brackets) {
this.electricCharacter = new BracketElectricCharacterSupport(LanguageConfigurationRegistry, modeId, this.brackets, this._conf.__electricCharacterSupport);
}
this.electricCharacter = new BracketElectricCharacterSupport(LanguageConfigurationRegistry, modeId, this.brackets, this.characterPair.getAutoClosingPairs(), this._conf.__electricCharacterSupport);
this.wordDefinition = this._conf.wordPattern || DEFAULT_WORD_REGEXP;
}
......
......@@ -32,11 +32,11 @@ export class BracketElectricCharacterSupport implements modes.IRichEditElectricC
private contribution: IBracketElectricCharacterContribution;
private brackets: Brackets;
constructor(registry:LanguageConfigurationRegistryImpl, modeId: string, brackets: modes.IRichEditBrackets, contribution: IBracketElectricCharacterContribution) {
constructor(registry:LanguageConfigurationRegistryImpl, modeId: string, brackets: modes.IRichEditBrackets, autoClosePairs: modes.IAutoClosingPairConditional[], contribution: IBracketElectricCharacterContribution) {
this._registry = registry;
this._modeId = modeId;
this.contribution = contribution || {};
this.brackets = new Brackets(modeId, brackets, this.contribution.docComment);
this.brackets = new Brackets(modeId, brackets, autoClosePairs, this.contribution.docComment);
}
public getElectricCharacters(): string[]{
......@@ -66,12 +66,16 @@ export class Brackets {
private _modeId: string;
private _richEditBrackets: modes.IRichEditBrackets;
private _docComment: IDocComment;
private _complexAutoClosePairs: modes.IAutoClosingPairConditional[];
constructor(modeId: string, richEditBrackets: modes.IRichEditBrackets, docComment: IDocComment = null) {
constructor(modeId: string, richEditBrackets: modes.IRichEditBrackets, autoClosePairs: modes.IAutoClosingPairConditional[], docComment?: IDocComment) {
this._modeId = modeId;
this._richEditBrackets = richEditBrackets;
this._docComment = docComment ? docComment : null;
this._complexAutoClosePairs = autoClosePairs.filter(pair => pair.open.length > 1 && !!pair.close);
if (docComment) {
// IDocComment is legacy, only partially supported
this._complexAutoClosePairs.push({ open: docComment.open, close: docComment.close });
}
}
public getElectricCharacters():string[] {
......@@ -85,9 +89,9 @@ export class Brackets {
}
}
// Doc comments
if (this._docComment){
result.push(this._docComment.open.charAt(this._docComment.open.length - 1));
// auto close
for (let pair of this._complexAutoClosePairs) {
result.push(pair.open.charAt(pair.open.length - 1));
}
// Filter duplicate entries
......@@ -103,8 +107,8 @@ export class Brackets {
return null;
}
return (this._onElectricCharacterDocComment(context, offset) ||
this._onElectricCharacterStandardBrackets(context, offset));
return (this._onElectricAutoClose(context, offset) ||
this._onElectricAutoIndent(context, offset));
}
private containsTokenTypes(fullTokenSpec: string, tokensToLookFor: string): boolean {
......@@ -117,7 +121,7 @@ export class Brackets {
return true;
}
private _onElectricCharacterStandardBrackets(context: modes.ILineContext, offset: number): modes.IElectricAction {
private _onElectricAutoIndent(context: modes.ILineContext, offset: number): modes.IElectricAction {
if (!this._richEditBrackets || this._richEditBrackets.brackets.length === 0) {
return null;
......@@ -151,35 +155,44 @@ export class Brackets {
return null;
}
private _onElectricCharacterDocComment(context: modes.ILineContext, offset: number): modes.IElectricAction {
// We only auto-close, so do nothing if there is no closing part.
if (!this._docComment || !this._docComment.close) {
private _onElectricAutoClose(context: modes.ILineContext, offset: number): modes.IElectricAction {
if (!this._complexAutoClosePairs.length) {
return null;
}
var line = context.getLineContent();
var char: string = line[offset];
// See if the right electric character was pressed
if (char !== this._docComment.open.charAt(this._docComment.open.length - 1)) {
return null;
}
for (let i = 0; i < this._complexAutoClosePairs.length; i++) {
let pair = this._complexAutoClosePairs[i];
// If this line already contains the closing tag, do nothing.
if (line.indexOf(this._docComment.close, offset) >= 0) {
return null;
}
// See if the right electric character was pressed
if (char !== pair.open.charAt(pair.open.length - 1)) {
continue;
}
// If we're not in a documentation comment, do nothing.
var lastTokenIndex = context.findIndexOfOffset(offset);
if (! this.containsTokenTypes(context.getTokenType(lastTokenIndex), this._docComment.scope)) {
return null;
}
// If this line already contains the closing tag, do nothing.
if (line.indexOf(pair.close, offset) >= 0) {
continue;
}
if (line.substring(context.getTokenStartIndex(lastTokenIndex), offset+1/* include electric char*/) !== this._docComment.open) {
return null;
// check if the full open bracket matches
let lastTokenIndex = context.findIndexOfOffset(offset);
if (line.substring(context.getTokenStartIndex(lastTokenIndex), offset+1/* include electric char*/) !== pair.open) {
continue;
}
// If we're in a scope listen in 'notIn', do nothing
if (pair.notIn) {
let tokenType = context.getTokenType(lastTokenIndex);
if (pair.notIn.some(scope => this.containsTokenTypes(tokenType, scope))) {
continue;
}
}
return { appendText: pair.close};
}
return { appendText: this._docComment.close};
}
}
......@@ -9,8 +9,11 @@ import {parse} from 'vs/base/common/json';
import {readFile} from 'vs/base/node/pfs';
import {LanguageConfiguration} from 'vs/editor/common/modes/languageConfigurationRegistry';
import {IModeService} from 'vs/editor/common/services/modeService';
import {IAutoClosingPair} from 'vs/editor/common/modes';
import {IAutoClosingPair, IAutoClosingPairConditional} from 'vs/editor/common/modes';
import {LanguageConfigurationRegistry} from 'vs/editor/common/modes/languageConfigurationRegistry';
import {Extensions, IJSONContributionRegistry} from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import {Registry} from 'vs/platform/platform';
import {IJSONSchema} from 'vs/base/common/jsonSchema';
type CharacterPair = [string, string];
......@@ -22,8 +25,8 @@ interface ICommentRule {
interface ILanguageConfiguration {
comments?: ICommentRule;
brackets?: CharacterPair[];
autoClosingPairs?: CharacterPair[];
surroundingPairs?: CharacterPair[];
autoClosingPairs?: (CharacterPair | IAutoClosingPairConditional)[];
surroundingPairs?: (CharacterPair | IAutoClosingPair)[];
}
export class LanguageConfigurationFileHandler {
......@@ -92,10 +95,135 @@ export class LanguageConfigurationFileHandler {
LanguageConfigurationRegistry.register(modeId, richEditConfig);
}
private _mapCharacterPairs(pairs:CharacterPair[]): IAutoClosingPair[] {
private _mapCharacterPairs(pairs: (CharacterPair | IAutoClosingPairConditional)[]): IAutoClosingPairConditional[] {
return pairs.map(pair => {
let [open, close] = pair;
return { open: open, close: close };
if (Array.isArray(pair)) {
return { open: pair[0], close: pair[1] };
}
return <IAutoClosingPairConditional> pair;
});
}
}
const schemaId = 'vscode://schemas/language-configuration';
const schema: IJSONSchema = {
default: {
comments: {
blockComment: ['/*', '*/'],
lineComment: '//'
},
brackets: [ [ '(', ')' ], [ '[', ']' ] , [ '{', '}' ]],
autoClosingPairs: [ [ '(', ')' ], [ '[', ']' ] , [ '{', '}' ]],
surroundingPairs: [ [ '(', ')' ], [ '[', ']' ] , [ '{', '}' ]]
},
definitions: {
openBracket: {
type: 'string',
description: nls.localize('schema.openBracket', 'The opening bracket character or string sequence.')
},
closeBracket: {
type: 'string',
description: nls.localize('schema.closeBracket', 'The closing bracket character or string sequence.')
},
bracketPair: {
type: 'array',
items: [{
$ref: '#definitions/openBracket'
},{
$ref: '#definitions/closeBracket'
}]
}
},
properties: {
comments: {
default: {
comments: {
blockComment: ['/*', '*/'],
lineComment: '//'
}
},
description: nls.localize('schema.comments', 'Defines the comment symbols'),
type: 'object',
properties: {
blockComment: {
type: 'array',
description: nls.localize('schema.blockComments', 'Defines how block comments are marked.'),
items: [{
type: 'string',
description: nls.localize('schema.blockComment.begin', 'The character sequence that starts a block comment.')
},{
type: 'string',
description: nls.localize('schema.blockComment.end', 'The character sequence that ends a block comment.')
}]
},
lineComment: {
type: 'string',
description: nls.localize('schema.lineComment', 'The character sequence that starts a line comment.')
}
}
},
brackets: {
default: {
brackets: [ [ '(', ')' ], [ '[', ']' ] , [ '{', '}' ]]
},
description: nls.localize('schema.brackets', 'Defines the bracket symbols that increase or decrease the indentation.'),
type: 'array',
items: {
$ref: '#definitions/bracketPair'
}
},
autoClosingPairs: {
default: {
autoClosingPairs: [ [ '(', ')' ], [ '[', ']' ] , [ '{', '}' ]]
},
description: nls.localize('schema.autoClosingPairs', 'Defines the bracket pairs. When a opening bracket is entered, the closing bracket is inserted automatically.'),
type: 'array',
items: {
oneOf: [{
$ref: '#definitions/bracketPair'
},{
type: 'object',
properties: {
open: {
$ref: '#definitions/openBracket'
},
close: {
$ref: '#definitions/closeBracket'
},
notIn: {
type: 'array',
description: nls.localize('schema.autoClosingPairs.notIn', 'Defines a list of scopes where the auto pairs are disabled.'),
items: {
enum: ['string', 'comment']
}
}
}
}]
}
},
surroundingPairs: {
default: {
surroundingPairs: [ [ '(', ')' ], [ '[', ']' ] , [ '{', '}' ]]
},
description: nls.localize('schema.surroundingPairs', 'Defines the bracket pairs that can be used to surround a selected string.'),
type: 'array',
items: {
oneOf: [{
$ref: '#definitions/bracketPair'
},{
type: 'object',
properties: {
open: {
$ref: '#definitions/openBracket'
},
close: {
$ref: '#definitions/closeBracket'
}
}
}]
}
},
}
};
let schemaRegistry = <IJSONContributionRegistry>Registry.as(Extensions.JSONContribution);
schemaRegistry.registerSchema(schemaId, schema);
......@@ -10,8 +10,7 @@ import {createLineContextFromTokenText} from 'vs/editor/test/common/modesTestUti
suite('Editor Modes - Auto Indentation', () => {
test('Doc comments', () => {
var brackets = new Brackets('test', null,
{ scope: 'doc', open: '/**', lineStart: ' * ', close: ' */' });
var brackets = new Brackets('test', null, [{ open: '/**', close: ' */' }]);
assert.equal(brackets.onElectricCharacter(createLineContextFromTokenText([
{ text: '/**', type: 'doc' },
......
......@@ -2500,6 +2500,12 @@ declare namespace vscode {
* @deprecated
*/
brackets?: any;
/**
* This property is deprecated and not fully supported anymore by
* the editor (scope and lineStart are ignored).
* Use the the autoClosingPairs property in the language configuration file instead.
* @deprecated
*/
docComment?: {
scope: string;
open: string;
......@@ -2511,7 +2517,7 @@ declare namespace vscode {
/**
* **Deprecated** Do not use.
*
* @deprecated Use the language configuration file instead.
* @deprecated * Use the the autoClosingPairs property in the language configuration file instead.
*/
__characterPairSupport?: {
autoClosingPairs: {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册