Skip to content

Commit

Permalink
fix positioning of jsdoc comments (and block comments in general) by …
Browse files Browse the repository at this point in the history
…prepending them with two backticks ``

this means you now no longer need to add a lone `#` before comment blocks yourself. yey!
closes #1
  • Loading branch information
phil294 committed May 19, 2022
1 parent c65f0a0 commit 56b7982
Show file tree
Hide file tree
Showing 27 changed files with 57 additions and 43 deletions.
6 changes: 6 additions & 0 deletions server/src/services/transpileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ function preprocess_coffee(coffee_doc: TextDocument) {
logger.logDebug(`transform a:b\nc\n to a:b\nc:c\n ${coffee_doc.uri}`)
return match + ':' + key
})
// Comment blocks ordering are often messed up without some workaround (issue #1)
// This also inserts `` before closing block comments but JSDoc doesn't seem to care
.replaceAll(/^(\s*)###($|[^#])/mg, (_, ws, c) => {
logger.logDebug(`transform ^### to ^\`\`### ${coffee_doc.uri}`)
return ws + '``###' + c
})
const tmp_lines = tmp.split('\n')
const object_tweak_coffee_lines: number[] = []
const space_tweak_coffee_lines: { line: string, line_i: number }[] = []
Expand Down
10 changes: 8 additions & 2 deletions test/lsp/features/diagnostics/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ describe('Should find diagnostics', () => {
},
// be5e704: JSDoc errors shown at the next possible source code section
{
range: sameLineRange(12, 0, 26),
range: sameLineRange(11, 0, 26),
severity: vscode.DiagnosticSeverity.Error,
message: "Cannot find name 'ThisTypeDoesNotExist'."
}
},
// Issue #1: Keep multiple var/comment block combination in the right order
{
range: sameLineRange(14, 0, 16),
severity: vscode.DiagnosticSeverity.Error,
message: "Type 'string' is not assignable to type 'number'."
},
])
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
something_else = 1

#

### ###
{ abc } = abc: destructuring_with_comment_block_var_1: 123

Expand Down
4 changes: 2 additions & 2 deletions test/lsp/fixture/completion/inline-object-open-brace.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#

###*
# @typedef {{
# inline_obj_open_brace_prop_1: number
# }} inline_obj_open_brace_interface
###

#

###* @type {inline_obj_open_brace_interface} ###
inline_obj_open_brace = { inline_obj_open_brace_prop
2 changes: 1 addition & 1 deletion test/lsp/fixture/completion/inline-object-param-key.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#

###*
# @param one {{
# obj_inline_param_key_prop_1: number
Expand Down
4 changes: 2 additions & 2 deletions test/lsp/fixture/completion/jsdoc-spacing.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#

###*
# @typedef {{
# obj_completion_with_jsdoc_spacing_prop_1 : number ,
Expand All @@ -7,7 +7,7 @@
# }} Obj_completion_with_jsdoc_spacing_interface
###

#

###* @type {Obj_completion_with_jsdoc_spacing_interface} ###
obj_completion_with_jsdoc_spacing =

4 changes: 2 additions & 2 deletions test/lsp/fixture/completion/object-before-comment.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#

###*
# @typedef {{
# obj_before_comment_completion_prop_1: number,
# obj_before_comment_completion_prop_2: string
# }} Obj_before_comment_completion_interface
###

#

###* @type {Obj_before_comment_completion_interface} ###
obj_before_comment_completion =

Expand Down
4 changes: 2 additions & 2 deletions test/lsp/fixture/completion/object-before-statement.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#

###*
# @typedef {{
# obj_completion_before_statement_prop_1: number,
# obj_completion_before_statement_prop_2: string
# }} Obj_completion_before_statement_interface
###

#

###* @type {Obj_completion_before_statement_interface} ###
obj_completion_before_statement =

Expand Down
4 changes: 2 additions & 2 deletions test/lsp/fixture/completion/object-half-defined-above.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#

###*
# @typedef {{
# obj_halfdefined_above_completion_prop_1: number,
# obj_halfdefined_above_completion_prop_2: string
# }} Obj_halfdefined_above_completion_interface
###

#

###* @type {Obj_halfdefined_above_completion_interface} ###
obj_halfdefined_above_completion =

Expand Down
4 changes: 2 additions & 2 deletions test/lsp/fixture/completion/object-half-defined.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#

###*
# @typedef {{
# obj_halfdefined_completion_prop_1: number,
# obj_halfdefined_completion_prop_2: string
# }} Obj_halfdefined_completion_interface
###

#

###* @type {Obj_halfdefined_completion_interface} ###
obj_halfdefined_completion =
obj_halfdefined_completion_prop_1: 123
Expand Down
4 changes: 2 additions & 2 deletions test/lsp/fixture/completion/object-half-line-colon.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#

###*
# @typedef {{
# obj_half_line_colon_completion_prop_1: number,
# obj_half_line_colon_completion_prop_2: string
# }} Obj_half_line_colon_completion_interface
###

#

###* @type {Obj_half_line_colon_completion_interface} ###
obj_half_line_colon_completion =
obj_half_line_colon_completion_prop:
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#

###*
# @typedef {{
# obj_half_line_half_defined_above_completion_prop_1: number,
# obj_half_line_half_defined_above_completion_prop_2: string
# }} Obj_half_line_half_defined_above_completion_interface
###

#

###* @type {Obj_half_line_half_defined_above_completion_interface} ###
obj_half_line_half_defined_above_completion =
obj_half_line_half_defined_above_completion_prop_
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#

###*
# @typedef {{
# obj_half_line_half_defined_completion_prop_1: number,
# obj_half_line_half_defined_completion_prop_2: string
# }} Obj_half_line_half_defined_completion_interface
###

#

###* @type {Obj_half_line_half_defined_completion_interface} ###
obj_half_line_half_defined_completion =
obj_half_line_half_defined_completion_prop_1: 123
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#

###*
# @typedef {{
# obj_half_line_with_braces_completion_prop_1: number,
# obj_half_line_with_braces_completion_prop_2: string
# }} Obj_half_line_with_braces_completion_interface
###

#

###* @type {Obj_half_line_with_braces_completion_interface} ###
obj_half_line_with_braces_completion = {
obj_half_line_with_braces_completion_prop
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#

###*
# @typedef {{
# obj_half_line_with_open_brace_completion_prop_1: number,
# obj_half_line_with_open_brace_completion_prop_2: string
# }} Obj_half_line_with_open_brace_completion_interface
###

#

###* @type {Obj_half_line_with_open_brace_completion_interface} ###
obj_half_line_with_open_brace_completion = {
obj_half_line_with_open_brace_completion_prop
4 changes: 2 additions & 2 deletions test/lsp/fixture/completion/object-half-line.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#

###*
# @typedef {{
# obj_half_line_completion_prop_1: number,
# obj_half_line_completion_prop_2: string
# }} Obj_half_line_completion_interface
###

#

###* @type {Obj_half_line_completion_interface} ###
obj_half_line_completion =
obj_half_line_completion_prop
4 changes: 2 additions & 2 deletions test/lsp/fixture/completion/object-invalid-line.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#

###*
# @typedef {{
# obj_invalid_line_completion_prop_1: number,
# obj_invalid_line_completion_prop_2: string
# }} Obj_invalid_line_completion_interface
###

#

###* @type {Obj_invalid_line_completion_interface} ###
obj_invalid_line_completion =
obj_invalid_line_completion_p : ~~var
4 changes: 2 additions & 2 deletions test/lsp/fixture/completion/object.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#

###*
# @typedef {{
# obj_completion_prop_1: number,
# obj_completion_prop_2: string
# }} Obj_completion_interface
###

#

###* @type {Obj_completion_interface} ###
obj_completion =

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#

###* @param val {'abc' | 'def'} ###
open_empty_string_as_function_param = (val) =>

Expand Down
2 changes: 1 addition & 1 deletion test/lsp/fixture/completion/open-string-2.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#

###* @type {"abc" | "def"} ###
open_string_var_2 = "
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#

###* @param val {'abc' | 'def'} ###
open_string_as_function_param_2 = (val) =>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#

###* @param val {'abc' | 'def'} ###
open_string_as_function_param = (val) =>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#

###* @param val {'abc' | 'def'} ###
open_string_as_function_no_brace_param = (val) =>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#@ts-check
#

###* @type {{abc:"def"|"ghi"}} ###
open_string_as_inline_obj_var = abc: "
Expand Down
2 changes: 1 addition & 1 deletion test/lsp/fixture/completion/open-string.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#

###* @type {"abc" | "def"} ###
open_string_var = "
4 changes: 2 additions & 2 deletions test/lsp/fixture/completion/string.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#

###* @type {'constant'} ###
string_completion_const = ''
#

###* @type {'constant'} ###
string_completion_const2 = 'constan'
6 changes: 4 additions & 2 deletions test/lsp/fixture/diagnostics/ts.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ diagnostics_ts = '1'
ts_check_func = (###* @type {string} ### param1) =>
ts_check_func 123

#
###*
# @type {ThisTypeDoesNotExist}
###
ts_type_does_not_exist_var = 123
ts_type_does_not_exist_var = 123

###* @type {number} ###
diagnostics_ts_2 = '1'

0 comments on commit 56b7982

Please sign in to comment.