Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Scala] Fix with keyword after comments in class declarations #3779

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Scala/Scala.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@ contexts:
# this is included when a single newline is found in a declaration
# you should never push/set this context, only include
decl-newline-double-check:
- include: block-comments
- match: ((//).*)\n
captures:
1: comment.line.double-slash.scala
2: punctuation.definition.comment.scala
- match: '(?=[\{\}\)]|\b(?:case|class|def|val|var|trait|object|private|protected|for|while|if|final|sealed|implicit|type|import|override)\b)'
pop: true
- match: '\n'
Expand All @@ -542,6 +547,7 @@ contexts:
set: function-type-parameter-list-newline

function-type-parameter-list-newline:
- meta_include_prototype: false
- include: decl-newline-double-check
- match: '(?=\S)'
set: function-type-parameter-list
Expand All @@ -567,6 +573,7 @@ contexts:
pop: true

function-return-type-definition-newline:
- meta_include_prototype: false
- include: decl-newline-double-check
- match: '(?=\S)'
set: function-return-type-definition
Expand Down Expand Up @@ -607,6 +614,7 @@ contexts:
pop: true

function-parameter-list-newline:
- meta_include_prototype: false
- include: decl-newline-double-check
- match: '(?=\S)'
set: function-parameter-list
Expand Down Expand Up @@ -634,6 +642,7 @@ contexts:
pop: true

class-type-parameter-list-newline:
- meta_include_prototype: false
- include: decl-newline-double-check
- match: '(?=\S)'
set: class-type-parameter-list
Expand Down Expand Up @@ -692,6 +701,7 @@ contexts:
pop: true

class-parameter-list-newline:
- meta_include_prototype: false
- include: decl-newline-double-check
- match: '(?=\S)'
set: class-parameter-list
Expand All @@ -713,6 +723,7 @@ contexts:
set: class-pre-inheritance-early-initializer-newline

class-pre-inheritance-early-initializer-newline:
- meta_include_prototype: false
- include: decl-newline-double-check
- match: '(?=\S)'
set: class-pre-inheritance-early-initializer
Expand All @@ -732,6 +743,7 @@ contexts:
pop: true

class-inheritance-extends-newline:
- meta_include_prototype: false
- include: decl-newline-double-check
- match: '(?=\S)'
set: class-inheritance-extends
Expand Down Expand Up @@ -761,6 +773,7 @@ contexts:
pop: true

class-inheritance-extends-token-newline:
- meta_include_prototype: false
- include: decl-newline-double-check
- match: '(?=\S)'
set: class-inheritance-extends-token
Expand Down Expand Up @@ -791,6 +804,7 @@ contexts:
pop: true

class-inheritance-extends-token-after-newline:
- meta_include_prototype: false
- include: decl-newline-double-check
- match: '(?=\S)'
set: class-inheritance-extends-token-after
Expand All @@ -812,6 +826,7 @@ contexts:
set: class-inheritance-early-initializer-newline

class-inheritance-early-initializer-newline:
- meta_include_prototype: false
- include: decl-newline-double-check
- match: '(?=\S)'
set: class-inheritance-early-initializer
Expand All @@ -829,6 +844,7 @@ contexts:
pop: true

class-inheritance-with-newline:
- meta_include_prototype: false
- include: decl-newline-double-check
- match: '(?=\S)'
set: class-inheritance-with
Expand Down Expand Up @@ -1876,11 +1892,13 @@ contexts:
set: single-type-expression

single-type-expression-tail-no-function-newline:
- meta_include_prototype: false
- include: decl-newline-double-check
- match: '(?=\S)'
set: single-type-expression-no-function

single-type-expression-tail-newline:
- meta_include_prototype: false
- include: decl-newline-double-check
- match: '(?=\S)'
set: single-type-expression
35 changes: 35 additions & 0 deletions Scala/syntax_test_scala.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,41 @@ class Foo extends Bar
// ^^^^ storage.modifier.with.scala
// ^^^ entity.other.inherited-class.scala

class c()
extends a()

with foo with bar {}
// ^^^^ invalid.keyword.dangling-with.scala
// ^^^^ invalid.keyword.dangling-with.scala

class c()
extends a()
/* some comment */
with foo with bar {}
// ^^^^ invalid.keyword.dangling-with.scala
// ^^^^ invalid.keyword.dangling-with.scala

class c()
extends a()
// some comment
with foo with bar {}
// ^^^^ storage.modifier.with.scala
// ^^^ entity.other.inherited-class.scala
// ^^^^ storage.modifier.with.scala
// ^^^ entity.other.inherited-class.scala
// ^^ meta.class.body.scala

class c()
extends a()
// some comment
// some comment
with foo with bar {}
// ^^^^ storage.modifier.with.scala
// ^^^ entity.other.inherited-class.scala
// ^^^^ storage.modifier.with.scala
// ^^^ entity.other.inherited-class.scala
// ^^ meta.class.body.scala

def foo
42
// ^^ meta.number.integer.decimal.scala
Expand Down