From d02fddf6398df481514df5c42c48143c9141120d Mon Sep 17 00:00:00 2001 From: phil294 Date: Sat, 21 May 2022 03:04:56 +0200 Subject: [PATCH] fix completion after dot after closing brace ) --- server/src/services/transpileService.ts | 6 +++--- test/lsp/features/completion/basic.test.ts | 4 ++++ test/lsp/fixture/completion/dot-after-closing-brace.coffee | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 test/lsp/fixture/completion/dot-after-closing-brace.coffee diff --git a/server/src/services/transpileService.ts b/server/src/services/transpileService.ts index c5213feb..d6946a75 100644 --- a/server/src/services/transpileService.ts +++ b/server/src/services/transpileService.ts @@ -281,7 +281,7 @@ const try_translate_coffee = (coffee_doc: TextDocument): ITranspilationResult => // Still need the `𒐩` to detect the fake js line further below if(try_fake_line_compilation( (coffee_error_line - .substring(0, coffee_error_line.length - end.length) + '𒐩' + .substring(0, coffee_error_line.length - end.length) + '.𒐩' ).trim())) { fake_line_mechanism = 'modified_js' fake_line_modified_js_end_removed = end @@ -339,9 +339,9 @@ const try_translate_coffee = (coffee_doc: TextDocument): ITranspilationResult => } else { const fake_js_line = js_fake_arr[js_fake_𒐩_line_no]! - const 𒐩_index = fake_js_line.indexOf('𒐩') + const 𒐩_index = fake_js_line.indexOf('.𒐩') const before_𒐩 = fake_js_line.slice(0, 𒐩_index) - const after_𒐩 = fake_js_line.slice(𒐩_index + 2) // 2 because 𒐩 is 2 chars in size?? Hopefully this is stable + const after_𒐩 = fake_js_line.slice(𒐩_index + 3) // 𒐩 is length 2 let tail = '' if(after_𒐩 !== ';') { // This is not really expected but can sometimes happen when fake line is being diff --git a/test/lsp/features/completion/basic.test.ts b/test/lsp/features/completion/basic.test.ts index 12ab810b..4e7c51a4 100644 --- a/test/lsp/features/completion/basic.test.ts +++ b/test/lsp/features/completion/basic.test.ts @@ -335,4 +335,8 @@ describe('Should autocomplete', () => { it('does not mess up indent in modified-js', async () => { await testCompletion({ doc_uri: getDocUri('completion/modified-js-indent.coffee'), position: position(2, 35), expected_items: ['modified_js_indent_prop'] }) }) + + it('completes after dot after closing brace', async () => { + await testCompletion({ doc_uri: getDocUri('completion/dot-after-closing-brace.coffee'), position: position(1, 14), expected_items: ['splice'], allow_unspecified: true }) + }) }) \ No newline at end of file diff --git a/test/lsp/fixture/completion/dot-after-closing-brace.coffee b/test/lsp/fixture/completion/dot-after-closing-brace.coffee new file mode 100644 index 00000000..fab015d9 --- /dev/null +++ b/test/lsp/fixture/completion/dot-after-closing-brace.coffee @@ -0,0 +1,2 @@ +aaa = ([] + .sort =>). \ No newline at end of file