diff --git a/src/common/constants.ts b/src/common/constants.ts index 909629c5..51834e3f 100644 --- a/src/common/constants.ts +++ b/src/common/constants.ts @@ -16,11 +16,12 @@ export const TokenClassConsts = { NUMBER_BINARY: 'number.binary', NUMBER_OCTAL: 'number.octal', NUMBER_HEX: 'number.hex', - OPERATOR: 'operators', - OPERATOR_KEYWORD: 'operators.keyword', - OPERATOR_SYMBOL: 'operators.symbol', + OPERATOR: 'operator', + OPERATOR_KEYWORD: 'operator.keyword', + OPERATOR_SYMBOL: 'operator.symbol', PREDEFINED: 'predefined', STRING: 'string', + STRING_DOUBLE: 'string.double', STRING_ESCAPE: 'string.escape', TYPE: 'type', VARIABLE: 'variable', diff --git a/src/mysql/mysql.contribution.ts b/src/mysql/mysql.contribution.ts index a24e8132..bfdc0bd2 100644 --- a/src/mysql/mysql.contribution.ts +++ b/src/mysql/mysql.contribution.ts @@ -9,8 +9,8 @@ import { LanguageIdEnum } from '../common/constants'; registerLanguage({ id: LanguageIdEnum.MYSQL, - extensions: [], - aliases: ['MySQL'], + extensions: ['mysql'], + aliases: ['MySQL', 'mysql'], loader: () => import('./mysql') }); @@ -18,6 +18,6 @@ loadLanguage(LanguageIdEnum.MYSQL); setupLanguageFeatures({ languageId: LanguageIdEnum.MYSQL, - completionItems: false, + completionItems: true, diagnostics: true }); diff --git a/src/mysql/mysql.test.ts b/src/mysql/mysql.test.ts index 81341ab8..b72924e1 100644 --- a/src/mysql/mysql.test.ts +++ b/src/mysql/mysql.test.ts @@ -4,20 +4,21 @@ *--------------------------------------------------------------------------------------------*/ import { testTokenization } from '../test/testRunner'; +import { TokenClassConsts, postfixTokenClass } from '../common/constants'; testTokenization('mysql', [ // Comments [ { line: '-- a comment', - tokens: [{ startIndex: 0, type: 'comment.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.COMMENT) }] } ], [ { line: '---sticky -- comment', - tokens: [{ startIndex: 0, type: 'comment.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.COMMENT) }] } ], @@ -25,12 +26,12 @@ testTokenization('mysql', [ { line: '-almost a comment', tokens: [ - { startIndex: 0, type: 'operator.sql' }, - { startIndex: 1, type: 'identifier.sql' }, - { startIndex: 7, type: 'white.sql' }, - { startIndex: 8, type: 'identifier.sql' }, - { startIndex: 9, type: 'white.sql' }, - { startIndex: 10, type: 'keyword.sql' } + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.OPERATOR_SYMBOL) }, + { startIndex: 1, type: postfixTokenClass(TokenClassConsts.IDENTIFIER) }, + { startIndex: 7, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 8, type: postfixTokenClass(TokenClassConsts.IDENTIFIER) }, + { startIndex: 9, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 10, type: postfixTokenClass(TokenClassConsts.IDENTIFIER) } ] } ], @@ -39,9 +40,9 @@ testTokenization('mysql', [ { line: '/* a full line comment */', tokens: [ - { startIndex: 0, type: 'comment.quote.sql' }, - { startIndex: 2, type: 'comment.sql' }, - { startIndex: 23, type: 'comment.quote.sql' } + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.COMMENT_QUOTE) }, + { startIndex: 2, type: postfixTokenClass(TokenClassConsts.COMMENT) }, + { startIndex: 23, type: postfixTokenClass(TokenClassConsts.COMMENT_QUOTE) } ] } ], @@ -50,9 +51,9 @@ testTokenization('mysql', [ { line: '/* /// *** /// */', tokens: [ - { startIndex: 0, type: 'comment.quote.sql' }, - { startIndex: 2, type: 'comment.sql' }, - { startIndex: 15, type: 'comment.quote.sql' } + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.COMMENT_QUOTE) }, + { startIndex: 2, type: postfixTokenClass(TokenClassConsts.COMMENT) }, + { startIndex: 15, type: postfixTokenClass(TokenClassConsts.COMMENT_QUOTE) } ] } ], @@ -60,7 +61,7 @@ testTokenization('mysql', [ [ { line: '# comment', - tokens: [{ startIndex: 0, type: 'comment.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.COMMENT) }] } ], @@ -68,20 +69,20 @@ testTokenization('mysql', [ { line: 'declare @x int = /* a simple comment */ 1;', tokens: [ - { startIndex: 0, type: 'keyword.sql' }, - { startIndex: 7, type: 'white.sql' }, - { startIndex: 8, type: 'identifier.sql' }, - { startIndex: 10, type: 'white.sql' }, - { startIndex: 11, type: 'keyword.sql' }, - { startIndex: 14, type: 'white.sql' }, - { startIndex: 15, type: 'operator.sql' }, - { startIndex: 16, type: 'white.sql' }, - { startIndex: 17, type: 'comment.quote.sql' }, - { startIndex: 19, type: 'comment.sql' }, - { startIndex: 37, type: 'comment.quote.sql' }, - { startIndex: 39, type: 'white.sql' }, - { startIndex: 40, type: 'number.sql' }, - { startIndex: 41, type: 'delimiter.sql' } + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.KEYWORD) }, + { startIndex: 7, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 8, type: postfixTokenClass(TokenClassConsts.IDENTIFIER) }, + { startIndex: 10, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 11, type: postfixTokenClass(TokenClassConsts.TYPE) }, + { startIndex: 14, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 15, type: postfixTokenClass(TokenClassConsts.OPERATOR_SYMBOL) }, + { startIndex: 16, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 17, type: postfixTokenClass(TokenClassConsts.COMMENT_QUOTE) }, + { startIndex: 19, type: postfixTokenClass(TokenClassConsts.COMMENT) }, + { startIndex: 37, type: postfixTokenClass(TokenClassConsts.COMMENT_QUOTE) }, + { startIndex: 39, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 40, type: postfixTokenClass(TokenClassConsts.NUMBER) }, + { startIndex: 41, type: postfixTokenClass(TokenClassConsts.DELIMITER) } ] } ], @@ -92,12 +93,12 @@ testTokenization('mysql', [ { line: '@x=/* a /* nested comment 1*/;', tokens: [ - { startIndex: 0, type: 'identifier.sql' }, - { startIndex: 2, type: 'operator.sql' }, - { startIndex: 3, type: 'comment.quote.sql' }, - { startIndex: 5, type: 'comment.sql' }, - { startIndex: 28, type: 'comment.quote.sql' }, - { startIndex: 30, type: 'delimiter.sql' } + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.IDENTIFIER) }, + { startIndex: 2, type: postfixTokenClass(TokenClassConsts.OPERATOR_SYMBOL) }, + { startIndex: 3, type: postfixTokenClass(TokenClassConsts.COMMENT_QUOTE) }, + { startIndex: 5, type: postfixTokenClass(TokenClassConsts.COMMENT) }, + { startIndex: 28, type: postfixTokenClass(TokenClassConsts.COMMENT_QUOTE) }, + { startIndex: 30, type: postfixTokenClass(TokenClassConsts.DELIMITER) } ] } ], @@ -106,15 +107,15 @@ testTokenization('mysql', [ { line: '@x=/* another comment */ 1*/;', tokens: [ - { startIndex: 0, type: 'identifier.sql' }, - { startIndex: 2, type: 'operator.sql' }, - { startIndex: 3, type: 'comment.quote.sql' }, - { startIndex: 5, type: 'comment.sql' }, - { startIndex: 22, type: 'comment.quote.sql' }, - { startIndex: 24, type: 'white.sql' }, - { startIndex: 25, type: 'number.sql' }, - { startIndex: 26, type: 'operator.sql' }, - { startIndex: 28, type: 'delimiter.sql' } + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.IDENTIFIER) }, + { startIndex: 2, type: postfixTokenClass(TokenClassConsts.OPERATOR_SYMBOL) }, + { startIndex: 3, type: postfixTokenClass(TokenClassConsts.COMMENT_QUOTE) }, + { startIndex: 5, type: postfixTokenClass(TokenClassConsts.COMMENT) }, + { startIndex: 22, type: postfixTokenClass(TokenClassConsts.COMMENT_QUOTE) }, + { startIndex: 24, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 25, type: postfixTokenClass(TokenClassConsts.NUMBER) }, + { startIndex: 26, type: postfixTokenClass(TokenClassConsts.OPERATOR_SYMBOL) }, + { startIndex: 28, type: postfixTokenClass(TokenClassConsts.DELIMITER) } ] } ], @@ -123,10 +124,10 @@ testTokenization('mysql', [ { line: '@x=/*/;', tokens: [ - { startIndex: 0, type: 'identifier.sql' }, - { startIndex: 2, type: 'operator.sql' }, - { startIndex: 3, type: 'comment.quote.sql' }, - { startIndex: 5, type: 'comment.sql' } + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.IDENTIFIER) }, + { startIndex: 2, type: postfixTokenClass(TokenClassConsts.OPERATOR_SYMBOL) }, + { startIndex: 3, type: postfixTokenClass(TokenClassConsts.COMMENT_QUOTE) }, + { startIndex: 5, type: postfixTokenClass(TokenClassConsts.COMMENT) } ] } ], @@ -135,7 +136,7 @@ testTokenization('mysql', [ [ { line: '123', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], @@ -143,8 +144,8 @@ testTokenization('mysql', [ { line: '-123', tokens: [ - { startIndex: 0, type: 'operator.sql' }, - { startIndex: 1, type: 'number.sql' } + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.OPERATOR_SYMBOL) }, + { startIndex: 1, type: postfixTokenClass(TokenClassConsts.NUMBER) } ] } ], @@ -152,28 +153,21 @@ testTokenization('mysql', [ [ { line: '0xaBc123', - tokens: [{ startIndex: 0, type: 'number.sql' }] - } - ], - - [ - { - line: '0XaBc123', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER_HEX) }] } ], [ { line: '0x', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER_HEX) }] } ], [ { line: '0x0', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER_HEX) }] } ], @@ -181,8 +175,8 @@ testTokenization('mysql', [ { line: '0xAB_CD', tokens: [ - { startIndex: 0, type: 'number.sql' }, - { startIndex: 4, type: 'identifier.sql' } + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER_HEX) }, + { startIndex: 4, type: postfixTokenClass(TokenClassConsts.IDENTIFIER) } ] } ], @@ -190,161 +184,161 @@ testTokenization('mysql', [ [ { line: '$', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '$-123', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '$-+-123', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '$123.5678', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '$0.99', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '$.99', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '$99.', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '$0.', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '$.0', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '.', - tokens: [{ startIndex: 0, type: 'delimiter.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.DELIMITER) }] } ], [ { line: '123', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '123.5678', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '0.99', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '.99', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '99.', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '0.', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '.0', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '1E-2', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '1E+2', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '1E2', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '0.1E2', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '1.E2', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], [ { line: '.1E2', - tokens: [{ startIndex: 0, type: 'number.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.NUMBER) }] } ], @@ -354,12 +348,10 @@ testTokenization('mysql', [ { line: 'declare `abc 321`;', tokens: [ - { startIndex: 0, type: 'keyword.sql' }, - { startIndex: 7, type: 'white.sql' }, - { startIndex: 8, type: 'identifier.quote.sql' }, - { startIndex: 9, type: 'identifier.sql' }, - { startIndex: 16, type: 'identifier.quote.sql' }, - { startIndex: 17, type: 'delimiter.sql' } + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.KEYWORD) }, + { startIndex: 7, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 8, type: postfixTokenClass(TokenClassConsts.IDENTIFIER_QUOTE) }, + { startIndex: 17, type: postfixTokenClass(TokenClassConsts.DELIMITER) } ] } ], @@ -367,74 +359,28 @@ testTokenization('mysql', [ [ { line: '`abc`` 321 `` xyz`', - tokens: [ - { startIndex: 0, type: 'identifier.quote.sql' }, - { startIndex: 1, type: 'identifier.sql' }, - { startIndex: 17, type: 'identifier.quote.sql' } - ] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.IDENTIFIER_QUOTE) }] } ], [ { line: '`abc', - tokens: [ - { startIndex: 0, type: 'identifier.quote.sql' }, - { startIndex: 1, type: 'identifier.sql' } - ] - } - ], - - [ - { - line: 'declare `abc 321`;', - tokens: [ - { startIndex: 0, type: 'keyword.sql' }, - { startIndex: 7, type: 'white.sql' }, - { startIndex: 8, type: 'identifier.quote.sql' }, - { startIndex: 9, type: 'identifier.sql' }, - { startIndex: 16, type: 'identifier.quote.sql' }, - { startIndex: 17, type: 'delimiter.sql' } - ] - } - ], - - [ - { - line: '`abc`` 321 `` xyz`', - tokens: [ - { startIndex: 0, type: 'identifier.quote.sql' }, - { startIndex: 1, type: 'identifier.sql' }, - { startIndex: 17, type: 'identifier.quote.sql' } - ] - } - ], - - [ - { - line: '`abc', - tokens: [ - { startIndex: 0, type: 'identifier.quote.sql' }, - { startIndex: 1, type: 'identifier.sql' } - ] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.IDENTIFIER_QUOTE) }] } ], [ { line: 'int', - tokens: [{ startIndex: 0, type: 'keyword.sql' }] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.TYPE) }] } ], [ { line: '`int`', - tokens: [ - { startIndex: 0, type: 'identifier.quote.sql' }, - { startIndex: 1, type: 'identifier.sql' }, - { startIndex: 4, type: 'identifier.quote.sql' } - ] + tokens: [{ startIndex: 0, type: postfixTokenClass(TokenClassConsts.IDENTIFIER_QUOTE) }] } ], @@ -443,12 +389,14 @@ testTokenization('mysql', [ { line: "declare @x='a string';", tokens: [ - { startIndex: 0, type: 'keyword.sql' }, - { startIndex: 7, type: 'white.sql' }, - { startIndex: 8, type: 'identifier.sql' }, - { startIndex: 10, type: 'operator.sql' }, - { startIndex: 11, type: 'string.sql' }, - { startIndex: 21, type: 'delimiter.sql' } + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.KEYWORD) }, + { startIndex: 7, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 8, type: postfixTokenClass(TokenClassConsts.IDENTIFIER) }, + { startIndex: 10, type: postfixTokenClass(TokenClassConsts.OPERATOR_SYMBOL) }, + { startIndex: 11, type: postfixTokenClass(TokenClassConsts.STRING) }, + { startIndex: 12, type: postfixTokenClass(TokenClassConsts.STRING_ESCAPE) }, + { startIndex: 20, type: postfixTokenClass(TokenClassConsts.STRING) }, + { startIndex: 21, type: postfixTokenClass(TokenClassConsts.DELIMITER) } ] } ], @@ -457,12 +405,14 @@ testTokenization('mysql', [ { line: 'declare @x="a string";', tokens: [ - { startIndex: 0, type: 'keyword.sql' }, - { startIndex: 7, type: 'white.sql' }, - { startIndex: 8, type: 'identifier.sql' }, - { startIndex: 10, type: 'operator.sql' }, - { startIndex: 11, type: 'string.double.sql' }, - { startIndex: 21, type: 'delimiter.sql' } + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.KEYWORD) }, + { startIndex: 7, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 8, type: postfixTokenClass(TokenClassConsts.IDENTIFIER) }, + { startIndex: 10, type: postfixTokenClass(TokenClassConsts.OPERATOR_SYMBOL) }, + { startIndex: 11, type: postfixTokenClass(TokenClassConsts.STRING) }, + { startIndex: 12, type: postfixTokenClass(TokenClassConsts.STRING_ESCAPE) }, + { startIndex: 20, type: postfixTokenClass(TokenClassConsts.STRING) }, + { startIndex: 21, type: postfixTokenClass(TokenClassConsts.DELIMITER) } ] } ], @@ -470,56 +420,90 @@ testTokenization('mysql', [ [ { line: "'a '' string with quotes'", - tokens: [{ startIndex: 0, type: 'string.sql' }] + tokens: [ + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.STRING) }, + { startIndex: 1, type: postfixTokenClass(TokenClassConsts.STRING_ESCAPE) }, + { startIndex: 3, type: postfixTokenClass(TokenClassConsts.STRING) }, + { startIndex: 5, type: postfixTokenClass(TokenClassConsts.STRING_ESCAPE) }, + { startIndex: 24, type: postfixTokenClass(TokenClassConsts.STRING) } + ] } ], [ { line: '"a "" string with quotes"', - tokens: [{ startIndex: 0, type: 'string.double.sql' }] + tokens: [ + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.STRING) }, + { startIndex: 1, type: postfixTokenClass(TokenClassConsts.STRING_ESCAPE) }, + { startIndex: 3, type: postfixTokenClass(TokenClassConsts.STRING) }, + { startIndex: 5, type: postfixTokenClass(TokenClassConsts.STRING_ESCAPE) }, + { startIndex: 24, type: postfixTokenClass(TokenClassConsts.STRING) } + ] } ], [ { line: "'a \" string with quotes'", - tokens: [{ startIndex: 0, type: 'string.sql' }] + tokens: [ + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.STRING) }, + { startIndex: 1, type: postfixTokenClass(TokenClassConsts.STRING_ESCAPE) }, + { startIndex: 23, type: postfixTokenClass(TokenClassConsts.STRING) } + ] } ], [ { line: '"a ` string with quotes"', - tokens: [{ startIndex: 0, type: 'string.double.sql' }] + tokens: [ + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.STRING) }, + { startIndex: 1, type: postfixTokenClass(TokenClassConsts.STRING_ESCAPE) }, + { startIndex: 23, type: postfixTokenClass(TokenClassConsts.STRING) } + ] } ], [ { line: "'a -- string with comment'", - tokens: [{ startIndex: 0, type: 'string.sql' }] + tokens: [ + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.STRING) }, + { startIndex: 1, type: postfixTokenClass(TokenClassConsts.STRING_ESCAPE) }, + { startIndex: 25, type: postfixTokenClass(TokenClassConsts.STRING) } + ] } ], [ { line: '"a -- string with comment"', - tokens: [{ startIndex: 0, type: 'string.double.sql' }] + tokens: [ + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.STRING) }, + { startIndex: 1, type: postfixTokenClass(TokenClassConsts.STRING_ESCAPE) }, + { startIndex: 25, type: postfixTokenClass(TokenClassConsts.STRING) } + ] } ], [ { line: "'a endless string", - tokens: [{ startIndex: 0, type: 'string.sql' }] + tokens: [ + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.STRING) }, + { startIndex: 1, type: postfixTokenClass(TokenClassConsts.STRING_ESCAPE) } + ] } ], [ { line: '"a endless string', - tokens: [{ startIndex: 0, type: 'string.double.sql' }] + tokens: [ + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.STRING) }, + { startIndex: 1, type: postfixTokenClass(TokenClassConsts.STRING_ESCAPE) } + ] } ], @@ -528,13 +512,13 @@ testTokenization('mysql', [ { line: 'SET @x=@x+1', tokens: [ - { startIndex: 0, type: 'keyword.sql' }, - { startIndex: 3, type: 'white.sql' }, - { startIndex: 4, type: 'identifier.sql' }, - { startIndex: 6, type: 'operator.sql' }, - { startIndex: 7, type: 'identifier.sql' }, - { startIndex: 9, type: 'operator.sql' }, - { startIndex: 10, type: 'number.sql' } + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.TYPE) }, + { startIndex: 3, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 4, type: postfixTokenClass(TokenClassConsts.IDENTIFIER) }, + { startIndex: 6, type: postfixTokenClass(TokenClassConsts.OPERATOR_SYMBOL) }, + { startIndex: 7, type: postfixTokenClass(TokenClassConsts.IDENTIFIER) }, + { startIndex: 9, type: postfixTokenClass(TokenClassConsts.OPERATOR_SYMBOL) }, + { startIndex: 10, type: postfixTokenClass(TokenClassConsts.NUMBER) } ] } ], @@ -543,9 +527,9 @@ testTokenization('mysql', [ { line: '@x^=@x', tokens: [ - { startIndex: 0, type: 'identifier.sql' }, - { startIndex: 2, type: 'operator.sql' }, - { startIndex: 4, type: 'identifier.sql' } + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.IDENTIFIER) }, + { startIndex: 2, type: postfixTokenClass(TokenClassConsts.OPERATOR_SYMBOL) }, + { startIndex: 4, type: postfixTokenClass(TokenClassConsts.IDENTIFIER) } ] } ], @@ -554,15 +538,11 @@ testTokenization('mysql', [ { line: 'WHERE myfield IS NOT NULL', tokens: [ - { startIndex: 0, type: 'keyword.sql' }, - { startIndex: 5, type: 'white.sql' }, - { startIndex: 6, type: 'identifier.sql' }, - { startIndex: 13, type: 'white.sql' }, - { startIndex: 14, type: 'operator.sql' }, - { startIndex: 16, type: 'white.sql' }, - { startIndex: 17, type: 'operator.sql' }, - { startIndex: 20, type: 'white.sql' }, - { startIndex: 21, type: 'operator.sql' } + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.KEYWORD) }, + { startIndex: 5, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 6, type: postfixTokenClass(TokenClassConsts.IDENTIFIER) }, + { startIndex: 13, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 14, type: postfixTokenClass(TokenClassConsts.OPERATOR_KEYWORD) } ] } ], @@ -571,25 +551,25 @@ testTokenization('mysql', [ { line: 'SELECT * FROM tbl WHERE MyColumn IN (1,2)', tokens: [ - { startIndex: 0, type: 'keyword.sql' }, - { startIndex: 6, type: 'white.sql' }, - { startIndex: 7, type: 'operator.sql' }, - { startIndex: 8, type: 'white.sql' }, - { startIndex: 9, type: 'keyword.sql' }, - { startIndex: 13, type: 'white.sql' }, - { startIndex: 14, type: 'identifier.sql' }, - { startIndex: 17, type: 'white.sql' }, - { startIndex: 18, type: 'keyword.sql' }, - { startIndex: 23, type: 'white.sql' }, - { startIndex: 24, type: 'identifier.sql' }, - { startIndex: 32, type: 'white.sql' }, - { startIndex: 33, type: 'operator.sql' }, - { startIndex: 35, type: 'white.sql' }, - { startIndex: 36, type: 'delimiter.parenthesis.sql' }, - { startIndex: 37, type: 'number.sql' }, - { startIndex: 38, type: 'delimiter.sql' }, - { startIndex: 39, type: 'number.sql' }, - { startIndex: 40, type: 'delimiter.parenthesis.sql' } + { startIndex: 0, type: postfixTokenClass(TokenClassConsts.KEYWORD) }, + { startIndex: 6, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 7, type: postfixTokenClass(TokenClassConsts.OPERATOR_SYMBOL) }, + { startIndex: 8, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 9, type: postfixTokenClass(TokenClassConsts.KEYWORD) }, + { startIndex: 13, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 14, type: postfixTokenClass(TokenClassConsts.IDENTIFIER) }, + { startIndex: 17, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 18, type: postfixTokenClass(TokenClassConsts.KEYWORD) }, + { startIndex: 23, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 24, type: postfixTokenClass(TokenClassConsts.IDENTIFIER) }, + { startIndex: 32, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 33, type: postfixTokenClass(TokenClassConsts.OPERATOR_KEYWORD) }, + { startIndex: 35, type: postfixTokenClass(TokenClassConsts.WHITE) }, + { startIndex: 36, type: postfixTokenClass(TokenClassConsts.DELIMITER_PAREN) }, + { startIndex: 37, type: postfixTokenClass(TokenClassConsts.NUMBER) }, + { startIndex: 38, type: postfixTokenClass(TokenClassConsts.DELIMITER) }, + { startIndex: 39, type: postfixTokenClass(TokenClassConsts.NUMBER) }, + { startIndex: 40, type: postfixTokenClass(TokenClassConsts.DELIMITER_PAREN) } ] } ] diff --git a/src/mysql/mysql.ts b/src/mysql/mysql.ts index a3eafdc1..aa3d9800 100644 --- a/src/mysql/mysql.ts +++ b/src/mysql/mysql.ts @@ -3,6 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { TokenClassConsts } from '../common/constants'; import type { languages } from '../fillers/monaco-editor-core'; export const conf: languages.LanguageConfiguration = { @@ -37,238 +38,114 @@ export const language = { ignoreCase: true, brackets: [ - { open: '[', close: ']', token: 'delimiter.square' }, - { open: '(', close: ')', token: 'delimiter.parenthesis' } + { open: '[', close: ']', token: TokenClassConsts.DELIMITER_SQUARE }, + { open: '(', close: ')', token: TokenClassConsts.DELIMITER_PAREN } ], + // Only consider reserved keywords keywords: [ 'ACCESSIBLE', - 'ACCOUNT', - 'ACTION', 'ADD', - 'AFTER', - 'AGAINST', - 'AGGREGATE', - 'ALGORITHM', 'ALL', 'ALTER', - 'ALWAYS', - 'ANALYSE', 'ANALYZE', 'AND', - 'ANY', 'AS', 'ASC', - 'ASCII', 'ASENSITIVE', - 'AT', - 'AUTOEXTEND_SIZE', - 'AUTO_INCREMENT', - 'AVG', - 'AVG_ROW_LENGTH', - 'BACKUP', 'BEFORE', - 'BEGIN', 'BETWEEN', 'BIGINT', 'BINARY', - 'BINLOG', - 'BIT', 'BLOB', - 'BLOCK', - 'BOOL', - 'BOOLEAN', 'BOTH', - 'BTREE', 'BY', - 'BYTE', - 'CACHE', 'CALL', 'CASCADE', - 'CASCADED', 'CASE', - 'CATALOG_NAME', - 'CHAIN', 'CHANGE', - 'CHANGED', - 'CHANNEL', 'CHAR', 'CHARACTER', - 'CHARSET', 'CHECK', - 'CHECKSUM', - 'CIPHER', - 'CLASS_ORIGIN', - 'CLIENT', - 'CLOSE', - 'COALESCE', - 'CODE', 'COLLATE', - 'COLLATION', 'COLUMN', - 'COLUMNS', - 'COLUMN_FORMAT', - 'COLUMN_NAME', - 'COMMENT', - 'COMMIT', - 'COMMITTED', - 'COMPACT', - 'COMPLETION', - 'COMPRESSED', - 'COMPRESSION', - 'CONCURRENT', 'CONDITION', - 'CONNECTION', - 'CONSISTENT', 'CONSTRAINT', - 'CONSTRAINT_CATALOG', - 'CONSTRAINT_NAME', - 'CONSTRAINT_SCHEMA', - 'CONTAINS', - 'CONTEXT', 'CONTINUE', 'CONVERT', - 'CPU', 'CREATE', 'CROSS', 'CUBE', - 'CURRENT', + 'CUME_DIST', 'CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRENT_USER', 'CURSOR', - 'CURSOR_NAME', - 'DATA', 'DATABASE', 'DATABASES', - 'DATAFILE', - 'DATE', - 'DATETIME', - 'DAY', 'DAY_HOUR', 'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND', - 'DEALLOCATE', 'DEC', 'DECIMAL', 'DECLARE', 'DEFAULT', - 'DEFAULT_AUTH', - 'DEFINER', 'DELAYED', - 'DELAY_KEY_WRITE', 'DELETE', + 'DENSE_RANK', 'DESC', 'DESCRIBE', - 'DES_KEY_FILE', 'DETERMINISTIC', - 'DIAGNOSTICS', - 'DIRECTORY', - 'DISABLE', - 'DISCARD', - 'DISK', 'DISTINCT', 'DISTINCTROW', 'DIV', - 'DO', 'DOUBLE', 'DROP', 'DUAL', - 'DUMPFILE', - 'DUPLICATE', - 'DYNAMIC', 'EACH', 'ELSE', 'ELSEIF', - 'ENABLE', + 'EMPTY', 'ENCLOSED', - 'ENCRYPTION', - 'END', - 'ENDS', - 'ENGINE', - 'ENGINES', - 'ENUM', - 'ERROR', - 'ERRORS', - 'ESCAPE', 'ESCAPED', - 'EVENT', - 'EVENTS', - 'EVERY', - 'EXCHANGE', - 'EXECUTE', + 'EXCEPT', 'EXISTS', 'EXIT', - 'EXPANSION', - 'EXPIRE', 'EXPLAIN', - 'EXPORT', - 'EXTENDED', - 'EXTENT_SIZE', 'FALSE', - 'FAST', - 'FAULTS', 'FETCH', - 'FIELDS', - 'FILE', - 'FILE_BLOCK_SIZE', - 'FILTER', - 'FIRST', - 'FIXED', + 'FIRST_VALUE', 'FLOAT', 'FLOAT4', 'FLOAT8', - 'FLUSH', - 'FOLLOWS', 'FOR', 'FORCE', 'FOREIGN', - 'FORMAT', - 'FOUND', 'FROM', - 'FULL', 'FULLTEXT', 'FUNCTION', - 'GENERAL', 'GENERATED', - 'GEOMETRY', - 'GEOMETRYCOLLECTION', 'GET', - 'GET_FORMAT', - 'GLOBAL', 'GRANT', - 'GRANTS', 'GROUP', - 'GROUP_REPLICATION', - 'HANDLER', - 'HASH', + 'GROUPING', + 'GROUPS', 'HAVING', - 'HELP', 'HIGH_PRIORITY', - 'HOST', - 'HOSTS', - 'HOUR', 'HOUR_MICROSECOND', 'HOUR_MINUTE', 'HOUR_SECOND', - 'IDENTIFIED', 'IF', 'IGNORE', - 'IGNORE_SERVER_IDS', - 'IMPORT', + 'IN', 'INDEX', - 'INDEXES', 'INFILE', - 'INITIAL_SIZE', 'INNER', 'INOUT', 'INSENSITIVE', 'INSERT', - 'INSERT_METHOD', - 'INSTALL', - 'INSTANCE', 'INT', 'INT1', 'INT2', @@ -278,395 +155,167 @@ export const language = { 'INTEGER', 'INTERVAL', 'INTO', - 'INVOKER', - 'IO', 'IO_AFTER_GTIDS', 'IO_BEFORE_GTIDS', - 'IO_THREAD', - 'IPC', - 'ISOLATION', - 'ISSUER', + 'IS', 'ITERATE', 'JOIN', - 'JSON', + 'JSON_TABLE', 'KEY', 'KEYS', - 'KEY_BLOCK_SIZE', 'KILL', - 'LANGUAGE', - 'LAST', + 'LAG', + 'LAST_VALUE', + 'LATERAL', + 'LEAD', 'LEADING', 'LEAVE', - 'LEAVES', 'LEFT', - 'LESS', - 'LEVEL', 'LIKE', 'LIMIT', 'LINEAR', 'LINES', - 'LINESTRING', - 'LIST', 'LOAD', - 'LOCAL', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCK', - 'LOCKS', - 'LOGFILE', - 'LOGS', 'LONG', 'LONGBLOB', 'LONGTEXT', 'LOOP', 'LOW_PRIORITY', - 'MASTER', - 'MASTER_AUTO_POSITION', 'MASTER_BIND', - 'MASTER_CONNECT_RETRY', - 'MASTER_DELAY', - 'MASTER_HEARTBEAT_PERIOD', - 'MASTER_HOST', - 'MASTER_LOG_FILE', - 'MASTER_LOG_POS', - 'MASTER_PASSWORD', - 'MASTER_PORT', - 'MASTER_RETRY_COUNT', - 'MASTER_SERVER_ID', - 'MASTER_SSL', - 'MASTER_SSL_CA', - 'MASTER_SSL_CAPATH', - 'MASTER_SSL_CERT', - 'MASTER_SSL_CIPHER', - 'MASTER_SSL_CRL', - 'MASTER_SSL_CRLPATH', - 'MASTER_SSL_KEY', 'MASTER_SSL_VERIFY_SERVER_CERT', - 'MASTER_TLS_VERSION', - 'MASTER_USER', 'MATCH', 'MAXVALUE', - 'MAX_CONNECTIONS_PER_HOUR', - 'MAX_QUERIES_PER_HOUR', - 'MAX_ROWS', - 'MAX_SIZE', - 'MAX_STATEMENT_TIME', - 'MAX_UPDATES_PER_HOUR', - 'MAX_USER_CONNECTIONS', - 'MEDIUM', 'MEDIUMBLOB', 'MEDIUMINT', 'MEDIUMTEXT', - 'MEMORY', - 'MERGE', - 'MESSAGE_TEXT', - 'MICROSECOND', 'MIDDLEINT', - 'MIGRATE', - 'MINUTE', 'MINUTE_MICROSECOND', 'MINUTE_SECOND', - 'MIN_ROWS', 'MOD', - 'MODE', 'MODIFIES', - 'MODIFY', - 'MONTH', - 'MULTILINESTRING', - 'MULTIPOINT', - 'MULTIPOLYGON', - 'MUTEX', - 'MYSQL_ERRNO', - 'NAME', - 'NAMES', - 'NATIONAL', 'NATURAL', - 'NCHAR', - 'NDB', - 'NDBCLUSTER', - 'NEVER', - 'NEW', - 'NEXT', - 'NO', - 'NODEGROUP', - 'NONBLOCKING', - 'NONE', - 'NO_WAIT', + 'NOT', 'NO_WRITE_TO_BINLOG', - 'NUMBER', + 'NTH_VALUE', + 'NTILE', + 'NULL', 'NUMERIC', - 'NVARCHAR', - 'OFFSET', - 'OLD_PASSWORD', + 'OF', 'ON', - 'ONE', - 'ONLY', - 'OPEN', 'OPTIMIZE', 'OPTIMIZER_COSTS', 'OPTION', 'OPTIONALLY', - 'OPTIONS', 'OR', 'ORDER', 'OUT', 'OUTER', 'OUTFILE', - 'OWNER', - 'PACK_KEYS', - 'PAGE', - 'PARSER', - 'PARSE_GCOL_EXPR', - 'PARTIAL', + 'OVER', 'PARTITION', - 'PARTITIONING', - 'PARTITIONS', - 'PASSWORD', - 'PHASE', - 'PLUGIN', - 'PLUGINS', - 'PLUGIN_DIR', - 'POINT', - 'POLYGON', - 'PORT', - 'PRECEDES', + 'PERCENT_RANK', 'PRECISION', - 'PREPARE', - 'PRESERVE', - 'PREV', 'PRIMARY', - 'PRIVILEGES', 'PROCEDURE', - 'PROCESSLIST', - 'PROFILE', - 'PROFILES', - 'PROXY', 'PURGE', - 'QUARTER', - 'QUERY', - 'QUICK', 'RANGE', + 'RANK', 'READ', 'READS', - 'READ_ONLY', 'READ_WRITE', 'REAL', - 'REBUILD', - 'RECOVER', - 'REDOFILE', - 'REDO_BUFFER_SIZE', - 'REDUNDANT', + 'RECURSIVE', 'REFERENCES', 'REGEXP', - 'RELAY', - 'RELAYLOG', - 'RELAY_LOG_FILE', - 'RELAY_LOG_POS', - 'RELAY_THREAD', 'RELEASE', - 'RELOAD', - 'REMOVE', 'RENAME', - 'REORGANIZE', - 'REPAIR', 'REPEAT', - 'REPEATABLE', 'REPLACE', - 'REPLICATE_DO_DB', - 'REPLICATE_DO_TABLE', - 'REPLICATE_IGNORE_DB', - 'REPLICATE_IGNORE_TABLE', - 'REPLICATE_REWRITE_DB', - 'REPLICATE_WILD_DO_TABLE', - 'REPLICATE_WILD_IGNORE_TABLE', - 'REPLICATION', 'REQUIRE', - 'RESET', 'RESIGNAL', - 'RESTORE', 'RESTRICT', - 'RESUME', 'RETURN', - 'RETURNED_SQLSTATE', - 'RETURNS', - 'REVERSE', 'REVOKE', 'RIGHT', 'RLIKE', - 'ROLLBACK', - 'ROLLUP', - 'ROTATE', - 'ROUTINE', 'ROW', 'ROWS', - 'ROW_COUNT', - 'ROW_FORMAT', - 'RTREE', - 'SAVEPOINT', - 'SCHEDULE', + 'ROW_NUMBER', 'SCHEMA', 'SCHEMAS', - 'SCHEMA_NAME', - 'SECOND', 'SECOND_MICROSECOND', - 'SECURITY', 'SELECT', 'SENSITIVE', 'SEPARATOR', - 'SERIAL', - 'SERIALIZABLE', - 'SERVER', - 'SESSION', 'SET', - 'SHARE', 'SHOW', - 'SHUTDOWN', 'SIGNAL', - 'SIGNED', - 'SIMPLE', - 'SLAVE', - 'SLOW', 'SMALLINT', - 'SNAPSHOT', - 'SOCKET', - 'SOME', - 'SONAME', - 'SOUNDS', - 'SOURCE', 'SPATIAL', 'SPECIFIC', 'SQL', 'SQLEXCEPTION', 'SQLSTATE', 'SQLWARNING', - 'SQL_AFTER_GTIDS', - 'SQL_AFTER_MTS_GAPS', - 'SQL_BEFORE_GTIDS', 'SQL_BIG_RESULT', - 'SQL_BUFFER_RESULT', - 'SQL_CACHE', 'SQL_CALC_FOUND_ROWS', - 'SQL_NO_CACHE', 'SQL_SMALL_RESULT', - 'SQL_THREAD', - 'SQL_TSI_DAY', - 'SQL_TSI_HOUR', - 'SQL_TSI_MINUTE', - 'SQL_TSI_MONTH', - 'SQL_TSI_QUARTER', - 'SQL_TSI_SECOND', - 'SQL_TSI_WEEK', - 'SQL_TSI_YEAR', 'SSL', - 'STACKED', - 'START', 'STARTING', - 'STARTS', - 'STATS_AUTO_RECALC', - 'STATS_PERSISTENT', - 'STATS_SAMPLE_PAGES', - 'STATUS', - 'STOP', - 'STORAGE', 'STORED', 'STRAIGHT_JOIN', - 'STRING', - 'SUBCLASS_ORIGIN', - 'SUBJECT', - 'SUBPARTITION', - 'SUBPARTITIONS', - 'SUPER', - 'SUSPEND', - 'SWAPS', - 'SWITCHES', + 'SYSTEM', 'TABLE', - 'TABLES', - 'TABLESPACE', - 'TABLE_CHECKSUM', - 'TABLE_NAME', - 'TEMPORARY', - 'TEMPTABLE', 'TERMINATED', - 'TEXT', - 'THAN', 'THEN', - 'TIME', - 'TIMESTAMP', - 'TIMESTAMPADD', - 'TIMESTAMPDIFF', 'TINYBLOB', 'TINYINT', 'TINYTEXT', 'TO', 'TRAILING', - 'TRANSACTION', 'TRIGGER', - 'TRIGGERS', 'TRUE', - 'TRUNCATE', - 'TYPE', - 'TYPES', - 'UNCOMMITTED', - 'UNDEFINED', 'UNDO', - 'UNDOFILE', - 'UNDO_BUFFER_SIZE', - 'UNICODE', - 'UNINSTALL', 'UNION', 'UNIQUE', - 'UNKNOWN', 'UNLOCK', 'UNSIGNED', - 'UNTIL', 'UPDATE', - 'UPGRADE', 'USAGE', 'USE', - 'USER', - 'USER_RESOURCES', - 'USE_FRM', 'USING', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', - 'VALIDATION', - 'VALUE', 'VALUES', 'VARBINARY', 'VARCHAR', 'VARCHARACTER', - 'VARIABLES', 'VARYING', - 'VIEW', 'VIRTUAL', - 'WAIT', - 'WARNINGS', - 'WEEK', - 'WEIGHT_STRING', 'WHEN', 'WHERE', 'WHILE', + 'WINDOW', 'WITH', - 'WITHOUT', - 'WORK', - 'WRAPPER', 'WRITE', - 'X509', - 'XA', - 'XID', - 'XML', 'XOR', - 'YEAR', 'YEAR_MONTH', 'ZEROFILL' ], + // https://dev.mysql.com/doc/refman/8.0/en/non-typed-operators.html operators: [ 'AND', 'BETWEEN', 'IN', 'LIKE', 'NOT', + 'REGEXP', + 'EXISTS', + 'OF', 'OR', 'IS', 'NULL', @@ -676,8 +325,11 @@ export const language = { 'JOIN', 'LEFT', 'OUTER', - 'RIGHT' + 'RIGHT', + 'FULL', + 'CROSS' ], + // https://dev.mysql.com/doc/refman/8.0/en/built-in-function-reference.html builtinFunctions: [ 'ABS', 'ACOS', @@ -688,19 +340,11 @@ export const language = { 'ANY_VALUE', 'Area', 'AsBinary', - 'AsWKB', 'ASCII', 'ASIN', 'AsText', - 'AsWKT', - 'ASYMMETRIC_DECRYPT', - 'ASYMMETRIC_DERIVE', - 'ASYMMETRIC_ENCRYPT', - 'ASYMMETRIC_SIGN', - 'ASYMMETRIC_VERIFY', 'ATAN', 'ATAN2', - 'ATAN', 'AVG', 'BENCHMARK', 'BIN', @@ -710,11 +354,11 @@ export const language = { 'BIT_OR', 'BIT_XOR', 'Buffer', + 'CASE', 'CAST', 'CEIL', 'CEILING', 'Centroid', - 'CHAR', 'CHAR_LENGTH', 'CHARACTER_LENGTH', 'CHARSET', @@ -734,10 +378,6 @@ export const language = { 'COT', 'COUNT', 'CRC32', - 'CREATE_ASYMMETRIC_PRIV_KEY', - 'CREATE_ASYMMETRIC_PUB_KEY', - 'CREATE_DH_PARAMETERS', - 'CREATE_DIGEST', 'Crosses', 'CURDATE', 'CURRENT_DATE', @@ -746,7 +386,6 @@ export const language = { 'CURRENT_USER', 'CURTIME', 'DATABASE', - 'DATE', 'DATE_ADD', 'DATE_FORMAT', 'DATE_SUB', @@ -764,6 +403,7 @@ export const language = { 'Dimension', 'Disjoint', 'Distance', + 'DIV', 'ELT', 'ENCODE', 'ENCRYPT', @@ -784,16 +424,12 @@ export const language = { 'FROM_DAYS', 'FROM_UNIXTIME', 'GeomCollFromText', - 'GeometryCollectionFromText', 'GeomCollFromWKB', - 'GeometryCollectionFromWKB', 'GeometryCollection', 'GeometryN', 'GeometryType', 'GeomFromText', - 'GeometryFromText', 'GeomFromWKB', - 'GeometryFromWKB', 'GET_FORMAT', 'GET_LOCK', 'GLength', @@ -819,6 +455,9 @@ export const language = { 'IS_IPV4_COMPAT', 'IS_IPV4_MAPPED', 'IS_IPV6', + // 'IS NOT', + // 'IS NOT NULL', + // 'IS NULL', 'IS_USED_LOCK', 'IsClosed', 'IsEmpty', @@ -828,6 +467,7 @@ export const language = { 'JSON_ARRAY', 'JSON_ARRAY_APPEND', 'JSON_ARRAY_INSERT', + 'JSON_ARRAYAGG', 'JSON_CONTAINS', 'JSON_CONTAINS_PATH', 'JSON_DEPTH', @@ -836,25 +476,27 @@ export const language = { 'JSON_KEYS', 'JSON_LENGTH', 'JSON_MERGE', + 'JSON_MERGE_PATCH', 'JSON_MERGE_PRESERVE', 'JSON_OBJECT', + 'JSON_OBJECTAGG', + 'JSON_PRETTY', 'JSON_QUOTE', 'JSON_REMOVE', 'JSON_REPLACE', 'JSON_SEARCH', 'JSON_SET', + 'JSON_STORAGE_SIZE', 'JSON_TYPE', 'JSON_UNQUOTE', 'JSON_VALID', + 'LAST_DAY', 'LAST_INSERT_ID', 'LCASE', 'LEAST', - 'LEFT', 'LENGTH', 'LineFromText', - 'LineStringFromText', 'LineFromWKB', - 'LineStringFromWKB', 'LineString', 'LN', 'LOAD_FILE', @@ -871,6 +513,7 @@ export const language = { 'MAKEDATE', 'MAKETIME', 'MASTER_POS_WAIT', + 'MATCH', 'MAX', 'MBRContains', 'MBRCoveredBy', @@ -883,30 +526,27 @@ export const language = { 'MBRTouches', 'MBRWithin', 'MD5', + 'MEMBER', 'MICROSECOND', 'MID', 'MIN', 'MINUTE', 'MLineFromText', - 'MultiLineStringFromText', 'MLineFromWKB', - 'MultiLineStringFromWKB', 'MOD', 'MONTH', 'MONTHNAME', 'MPointFromText', - 'MultiPointFromText', 'MPointFromWKB', - 'MultiPointFromWKB', 'MPolyFromText', - 'MultiPolygonFromText', 'MPolyFromWKB', - 'MultiPolygonFromWKB', 'MultiLineString', 'MultiPoint', 'MultiPolygon', 'NAME_CONST', - 'NOT IN', + // 'NOT IN', + // 'NOT LIKE', + // 'NOT REGEXP', 'NOW', 'NULLIF', 'NumGeometries', @@ -914,7 +554,6 @@ export const language = { 'NumPoints', 'OCT', 'OCTET_LENGTH', - 'OLD_PASSWORD', 'ORD', 'Overlaps', 'PASSWORD', @@ -926,14 +565,12 @@ export const language = { 'PointFromWKB', 'PointN', 'PolyFromText', - 'PolygonFromText', 'PolyFromWKB', - 'PolygonFromWKB', 'Polygon', 'POSITION', 'POW', 'POWER', - 'PROCEDURE ANALYSE', + // 'PROCEDURE ANALYSE', 'QUARTER', 'QUOTE', 'RADIANS', @@ -944,7 +581,7 @@ export const language = { 'REPEAT', 'REPLACE', 'REVERSE', - 'RIGHT', + 'RLIKE', 'ROUND', 'ROW_COUNT', 'RPAD', @@ -954,21 +591,19 @@ export const language = { 'SECOND', 'SESSION_USER', 'SHA1', - 'SHA', 'SHA2', 'SIGN', 'SIN', 'SLEEP', 'SOUNDEX', + // 'SOUNDS LIKE', 'SPACE', 'SQRT', 'SRID', 'ST_Area', 'ST_AsBinary', - 'ST_AsWKB', 'ST_AsGeoJSON', 'ST_AsText', - 'ST_AsWKT', 'ST_Buffer', 'ST_Buffer_Strategy', 'ST_Centroid', @@ -986,17 +621,12 @@ export const language = { 'ST_ExteriorRing', 'ST_GeoHash', 'ST_GeomCollFromText', - 'ST_GeometryCollectionFromText', - 'ST_GeomCollFromTxt', 'ST_GeomCollFromWKB', - 'ST_GeometryCollectionFromWKB', 'ST_GeometryN', 'ST_GeometryType', 'ST_GeomFromGeoJSON', 'ST_GeomFromText', - 'ST_GeometryFromText', 'ST_GeomFromWKB', - 'ST_GeometryFromWKB', 'ST_InteriorRingN', 'ST_Intersection', 'ST_Intersects', @@ -1007,26 +637,17 @@ export const language = { 'ST_LatFromGeoHash', 'ST_Length', 'ST_LineFromText', - 'ST_LineStringFromText', 'ST_LineFromWKB', - 'ST_LineStringFromWKB', 'ST_LongFromGeoHash', 'ST_MakeEnvelope', 'ST_MLineFromText', - 'ST_MultiLineStringFromText', 'ST_MLineFromWKB', - 'ST_MultiLineStringFromWKB', 'ST_MPointFromText', - 'ST_MultiPointFromText', 'ST_MPointFromWKB', - 'ST_MultiPointFromWKB', 'ST_MPolyFromText', - 'ST_MultiPolygonFromText', 'ST_MPolyFromWKB', - 'ST_MultiPolygonFromWKB', 'ST_NumGeometries', 'ST_NumInteriorRing', - 'ST_NumInteriorRings', 'ST_NumPoints', 'ST_Overlaps', 'ST_PointFromGeoHash', @@ -1034,9 +655,7 @@ export const language = { 'ST_PointFromWKB', 'ST_PointN', 'ST_PolyFromText', - 'ST_PolygonFromText', 'ST_PolyFromWKB', - 'ST_PolygonFromWKB', 'ST_Simplify', 'ST_SRID', 'ST_StartPoint', @@ -1063,11 +682,9 @@ export const language = { 'SYSDATE', 'SYSTEM_USER', 'TAN', - 'TIME', 'TIME_FORMAT', 'TIME_TO_SEC', 'TIMEDIFF', - 'TIMESTAMP', 'TIMESTAMPADD', 'TIMESTAMPDIFF', 'TO_BASE64', @@ -1103,78 +720,265 @@ export const language = { 'WEIGHT_STRING', 'Within', 'X', + 'XOR', 'Y', - 'YEAR', - 'YEARWEEK' + 'YEARWEEK', + // The following function names are the new additions in v8.0 + 'asynchronous_connection_failover_add_managed', + 'asynchronous_connection_failover_add_source', + 'asynchronous_connection_failover_delete_managed', + 'asynchronous_connection_failover_delete_source', + 'asynchronous_connection_failover_reset', + 'BIN_TO_UUID', + 'CAN_ACCESS_COLUMN', + 'CAN_ACCESS_DATABASE', + 'CAN_ACCESS_TABLE', + 'CAN_ACCESS_USER', + 'CAN_ACCESS_VIEW', + 'CUME_DIST', + 'CURRENT_ROLE', + 'DENSE_RANK', + 'FIRST_VALUE', + 'FORMAT_BYTES', + 'FORMAT_PICO_TIME', + 'GeomCollection', + 'GET_DD_COLUMN_PRIVILEGES', + 'GET_DD_CREATE_OPTIONS', + 'GET_DD_INDEX_SUB_PART_LENGTH', + 'group_replication_disable_member_action', + 'group_replication_enable_member_action', + 'group_replication_get_communication_protocol', + 'group_replication_get_write_concurrency', + 'group_replication_reset_member_actions', + 'group_replication_set_as_primary', + 'group_replication_set_communication_protocol', + 'group_replication_set_write_concurrency', + 'group_replication_switch_to_multi_primary_mode', + 'group_replication_switch_to_single_primary_mode', + 'GROUPING', + 'ICU_VERSION', + 'INTERNAL_AUTO_INCREMENT', + 'INTERNAL_AVG_ROW_LENGTH', + 'INTERNAL_CHECK_TIME', + 'INTERNAL_CHECKSUM', + 'INTERNAL_DATA_FREE', + 'INTERNAL_DATA_LENGTH', + 'INTERNAL_DD_CHAR_LENGTH', + 'INTERNAL_GET_COMMENT_OR_ERROR', + 'INTERNAL_GET_ENABLED_ROLE_JSON', + 'INTERNAL_GET_HOSTNAME', + 'INTERNAL_GET_USERNAME', + 'INTERNAL_GET_VIEW_WARNING_OR_ERROR', + 'INTERNAL_INDEX_COLUMN_CARDINALITY', + 'INTERNAL_INDEX_LENGTH', + 'INTERNAL_IS_ENABLED_ROLE', + 'INTERNAL_IS_MANDATORY_ROLE', + 'INTERNAL_KEYS_DISABLED', + 'INTERNAL_MAX_DATA_LENGTH', + 'INTERNAL_TABLE_ROWS', + 'INTERNAL_UPDATE_TIME', + 'IS_UUID', + 'JSON_OVERLAPS', + 'JSON_SCHEMA_VALID', + 'JSON_SCHEMA_VALIDATION_REPORT', + 'JSON_STORAGE_FREE', + 'JSON_TABLE', + 'JSON_VALUE', + 'LAG', + 'LAST_VALUE', + 'LEAD', + // 'MEMBER OF', + 'NTH_VALUE', + 'NTILE', + 'PERCENT_RANK', + 'PS_CURRENT_THREAD_ID', + 'PS_THREAD_ID', + 'RANK', + 'REGEXP_INSTR', + 'REGEXP_LIKE', + 'REGEXP_REPLACE', + 'REGEXP_SUBSTR', + 'ROLES_GRAPHML', + 'ROW_NUMBER', + 'SOURCE_POS_WAIT', + 'ST_Collect', + 'ST_FrechetDistance', + 'ST_HausdorffDistance', + 'ST_Latitude', + 'ST_LineInterpolatePoint', + 'ST_LineInterpolatePoints', + 'ST_Longitude', + 'ST_PointAtDistance', + 'ST_SwapXY', + 'ST_Transform', + 'STATEMENT_DIGEST', + 'STATEMENT_DIGEST_TEXT', + 'UUID_TO_BIN' ], builtinVariables: [ // NOT SUPPORTED ], + // https://dev.mysql.com/doc/refman/8.0/en/storage-requirements.html + typeKeywords: [ + // Numeric Types + 'TINYINT', + 'SMALLINT', + 'MEDIUMINT', + 'INT', + 'INTEGER', + 'BIGINT', + 'FLOAT', + 'DOUBLE', + 'REAL', + 'DECIMAL', + 'NUMERIC', + 'BIT', + // Date and Time Types + 'YEAR', + 'DATE', + 'TIME', + 'DATETIME', + 'TIMESTAMP', + // String Types + 'CHAR', + 'BINARY', + 'VARCHAR', + 'VARBINARY', + 'TINYBLOB', + 'TINYTEXT', + 'BLOB', + 'TEXT', + 'MEDIUMBLOB', + 'MEDIUMTEXT', + 'LONGBLOB', + 'LONGTEXT', + 'ENUM', + 'SET', + // Spatial Types + 'GEOMETRY', + 'POINT', + 'LINESTRING', + 'POLYGON', + 'MULTIPOINT', + 'MULTILINESTRING', + 'MULTIPOLYGON', + 'GEOMETRYCOLLECTION', + // JSON Types + 'JSON', + 'JSON_STORAGE_SIZE', + 'JSON_SET', + 'JSON_INSERT', + 'JSON_REPLACE', + 'JSON_REMOVE', + 'JSON_STORAGE_FREE', + 'JSON_TYPE', + 'JSON_ARRAY', + 'JSON_OBJECT', + 'JSON_MERGE_PRESERVE', + 'JSON_MERGE_PATCH', + 'JSON_CONTAINS_PATH', + 'JSON_MERGE', + 'JSON_VALID', + 'JSON_UNQUOTE', + 'JSON_EXTRACT', + // Misc Types + 'BOOLEAN' + ], + scopeKeywords: ['BEGIN', 'CASE', 'END', 'WHEN', 'THEN', 'ELSE'], + pseudoColumns: [ + // Not support + ], tokenizer: { root: [ { include: '@comments' }, { include: '@whitespace' }, + { include: '@pseudoColumns' }, { include: '@numbers' }, { include: '@strings' }, { include: '@complexIdentifiers' }, { include: '@scopes' }, - [/[;,.]/, 'delimiter'], + { include: '@complexOperators' }, + [/[;,.]/, TokenClassConsts.DELIMITER], [/[()]/, '@brackets'], [ /[\w@]+/, { cases: { - '@keywords': 'keyword', - '@operators': 'operator', - '@builtinVariables': 'predefined', - '@builtinFunctions': 'predefined', - '@default': 'identifier' + '@scopeKeywords': TokenClassConsts.KEYWORD_SCOPE, + '@operators': TokenClassConsts.OPERATOR_KEYWORD, + '@typeKeywords': TokenClassConsts.TYPE, + '@builtinVariables': TokenClassConsts.VARIABLE, + '@builtinFunctions': TokenClassConsts.PREDEFINED, + '@keywords': TokenClassConsts.KEYWORD, + '@default': TokenClassConsts.IDENTIFIER } } ], - [/[<>=!%&+\-*/|~^]/, 'operator'] + [/[<>=!%&+\-*/|~^]/, TokenClassConsts.OPERATOR_SYMBOL] ], - whitespace: [[/\s+/, 'white']], comments: [ - [/--+.*/, 'comment'], - [/#+.*/, 'comment'], - [/\/\*/, { token: 'comment.quote', next: '@comment' }] + [/--+.*/, TokenClassConsts.COMMENT], + [/#+.*/, TokenClassConsts.COMMENT], + [/\/\*/, { token: TokenClassConsts.COMMENT_QUOTE, next: '@comment' }] ], + whitespace: [[/\s+/, TokenClassConsts.WHITE]], comment: [ - [/[^*/]+/, 'comment'], + [/[^*/]+/, TokenClassConsts.COMMENT], // Not supporting nested comments, as nested comments seem to not be standard? // i.e. http://stackoverflow.com/questions/728172/are-there-multiline-comment-delimiters-in-sql-that-are-vendor-agnostic // [/\/\*/, { token: 'comment.quote', next: '@push' }], // nested comment not allowed :-( - [/\*\//, { token: 'comment.quote', next: '@pop' }], - [/./, 'comment'] + [/\*\//, { token: TokenClassConsts.COMMENT_QUOTE, next: '@pop' }], + [/./, TokenClassConsts.COMMENT] + ], + pseudoColumns: [ + [ + /[$][A-Za-z_][\w@#$]*/, + { + cases: { + '@pseudoColumns': TokenClassConsts.PREDEFINED, + '@default': TokenClassConsts.IDENTIFIER + } + } + ] ], numbers: [ - [/0[xX][0-9a-fA-F]*/, 'number'], - [/[$][+-]*\d*(\.\d*)?/, 'number'], - [/((\d+(\.\d*)?)|(\.\d+))([eE][\-+]?\d+)?/, 'number'] + [/0[xX][0-9a-fA-F]*/, TokenClassConsts.NUMBER_HEX], + [/[$][+-]*\d*(\.\d*)?/, TokenClassConsts.NUMBER], + [/((\d+(\.\d*)?)|(\.\d+))([eE][\-+]?\d+)?/, TokenClassConsts.NUMBER] ], strings: [ - [/'/, { token: 'string', next: '@string' }], - [/"/, { token: 'string.double', next: '@stringDouble' }] + [/'/, { token: TokenClassConsts.STRING, next: '@stringSingle' }], + [/"/, { token: TokenClassConsts.STRING, next: '@stringDouble' }] ], - string: [ - [/[^']+/, 'string'], - [/''/, 'string'], - [/'/, { token: 'string', next: '@pop' }] + stringSingle: [ + [/\\'/, TokenClassConsts.STRING_ESCAPE], + [/[^']+/, TokenClassConsts.STRING_ESCAPE], + [/''/, TokenClassConsts.STRING], + [/'/, { token: TokenClassConsts.STRING, next: '@pop' }] ], stringDouble: [ - [/[^"]+/, 'string.double'], - [/""/, 'string.double'], - [/"/, { token: 'string.double', next: '@pop' }] + [/[^"]+/, TokenClassConsts.STRING_ESCAPE], + [/""/, TokenClassConsts.STRING], + [/"/, { token: TokenClassConsts.STRING, next: '@pop' }] + ], + complexIdentifiers: [ + [/`/, { token: TokenClassConsts.IDENTIFIER_QUOTE, next: '@quotedIdentifier' }] ], - complexIdentifiers: [[/`/, { token: 'identifier.quote', next: '@quotedIdentifier' }]], quotedIdentifier: [ - [/[^`]+/, 'identifier'], - [/``/, 'identifier'], - [/`/, { token: 'identifier.quote', next: '@pop' }] + [/[^`]+/, TokenClassConsts.IDENTIFIER_QUOTE], + [/``/, TokenClassConsts.IDENTIFIER_QUOTE], + [/`/, { token: TokenClassConsts.IDENTIFIER_QUOTE, next: '@pop' }] ], scopes: [ // NOT SUPPORTED + ], + complexOperators: [ + [/IS\s+NOT\s+(NULL)?\b/i, { token: TokenClassConsts.OPERATOR_KEYWORD }], + [/IS\s+NULL\b/i, { token: TokenClassConsts.OPERATOR_KEYWORD }], + [/NOT\s+(IN|LIKE|REGEXP)\b/i, { token: TokenClassConsts.OPERATOR_KEYWORD }], + [/PROCEDURE\s+ANALYSE\b/i, { token: TokenClassConsts.OPERATOR_KEYWORD }], + [/SOUNDS\s+LIKE\b/i, { token: TokenClassConsts.OPERATOR_KEYWORD }], + [/MEMBER\s+OF\b/i, { token: TokenClassConsts.OPERATOR_KEYWORD }] ] } }; diff --git a/src/setupLanguageFeatures.ts b/src/setupLanguageFeatures.ts index 99431a1c..832461c9 100644 --- a/src/setupLanguageFeatures.ts +++ b/src/setupLanguageFeatures.ts @@ -80,7 +80,7 @@ function processConfiguration(configuration: FeatureConfiguration) { if ( // The following languages are not support codeCompletion now. - [LanguageIdEnum.MYSQL, LanguageIdEnum.PG, LanguageIdEnum.PL, LanguageIdEnum.SQL].includes( + [LanguageIdEnum.PG, LanguageIdEnum.PL, LanguageIdEnum.SQL].includes( languageId as LanguageIdEnum ) ) { diff --git a/website/src/languages/index.ts b/website/src/languages/index.ts index f7ef37d5..f5bc38e7 100644 --- a/website/src/languages/index.ts +++ b/website/src/languages/index.ts @@ -20,6 +20,11 @@ setupLanguageFeatures({ completionService }); +setupLanguageFeatures({ + languageId: LanguageIdEnum.MYSQL, + completionService +}); + setupLanguageFeatures({ languageId: LanguageIdEnum.TRINO, completionService