Skip to content

Commit

Permalink
fixed: new 'use' use cases is supported (such as single-line declarat…
Browse files Browse the repository at this point in the history
…ion, comma-separated list of imported rules names), additional tests, errors messages are were refactored, highlighting of Snakemake 'from', 'as' and 'with' keywords

Resolves: #355
  • Loading branch information
Dmitry Kochik committed Aug 2, 2021
1 parent 61a703b commit 0c79a6f
Show file tree
Hide file tree
Showing 16 changed files with 849 additions and 290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ object SmkSyntaxAnnotator : SmkAnnotator() {
var done = false
while (!done && next != null) {
when (next.elementType) {
SmkTokenTypes.RULE_KEYWORD -> addHighlightingAnnotation(next, PyHighlighter.PY_KEYWORD)
SmkTokenTypes.RULE_KEYWORD, SmkTokenTypes.SMK_FROM_KEYWORD,
SmkTokenTypes.SMK_AS_KEYWORD, SmkTokenTypes.SMK_WITH_KEYWORD -> addHighlightingAnnotation(
next,
PyHighlighter.PY_KEYWORD
)
SmkElementTypes.USE_NAME_IDENTIFIER, PyTokenTypes.IDENTIFIER -> addHighlightingAnnotation(
next, PY_FUNC_DEFINITION
)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ object SmkElementTypes {
SmkUseNameIdentifier(it)
}

val USE_IMPORTED_RULES_NAMES = PyElementType(
"USE_IMPORTED_RULES_NAMES"
) {
SmkImportedRulesNames(it)
}

val WORKFLOW_ARGS_SECTION_STATEMENT = PyElementType(
"SMK_WORKFLOW_ARGS_SECTION_STATEMENT"
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class SmkUseArgsSectionImpl(node: ASTNode) : SmkArgsSectionImpl(node), SmkRuleOr
}
}

override fun multilineSectionDefinition(): Boolean =
SmkRuleOrCheckpointArgsSectionImpl.multilineSectionDefinition(this)


override fun getType(context: TypeEvalContext, key: TypeEvalContext.Key): PyType =
SmkRuleLikeSectionArgsType(this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ package com.jetbrains.snakecharm.lang.psi.impl
import com.intellij.lang.ASTNode
import com.jetbrains.python.psi.impl.PyElementImpl

class SmkUseNameIdentifier(node: ASTNode) : PyElementImpl(node)
class SmkUseNameIdentifier(node: ASTNode) : PyElementImpl(node)

class SmkImportedRulesNames(node: ASTNode) : PyElementImpl(node)
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SmkRuleOrCheckpointNameReference(

results.addAll(SmkRulesType(null, smkFile).resolveMember(name, element, ctx, myContext))
results.addAll(SmkCheckpointType(null, smkFile).resolveMember(name, element, ctx, myContext))
results.addAll(SmkUsesType(null, smkFile).resolveMember(name, element, ctx, myContext))
//results.addAll(SmkUsesType(null, smkFile).resolveMember(name, element, ctx, myContext))
results.addAll(collectModulesAndResolveThem(smkFile, name))
results.addAll(collectModuleFromUseSection(element))

Expand Down Expand Up @@ -83,7 +83,12 @@ class SmkRuleOrCheckpointNameReference(
moduleRef = moduleRef.nextSibling
}
if (moduleRef != null) {
return SmkRuleOrCheckpointNameReference(moduleRef as SmkReferenceExpression, myContext).resolveInner()
return listOf(
RatedResolveResult(
SmkResolveUtil.RATE_NORMAL,
(moduleRef as SmkReferenceExpression).reference.resolve()
)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.stubs.StubElement
import com.jetbrains.snakecharm.lang.psi.SmkUse
import com.jetbrains.snakecharm.lang.psi.impl.SmkUseImpl
import com.jetbrains.snakecharm.lang.psi.stubs.SmkUseNameIndex.Companion.KEY
import com.jetbrains.snakecharm.lang.psi.stubs.SmkUseStub

class SmkUseElementType
: SmkRuleLikeElementType<SmkUseStub, SmkUse>("SMK_USE_DECLARATION_STATEMENT", KEY) {
: SmkRuleLikeElementType<SmkUseStub, SmkUse>("SMK_USE_DECLARATION_STATEMENT", null) {
//KEY) {

override fun createStub(name: String?, parentStub: StubElement<*>?): SmkUseStub =
SmkUseStubImpl(name, parentStub)
Expand Down
19 changes: 16 additions & 3 deletions src/main/resources/SnakemakeBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,22 @@ PARSE.expected.indent=Indent expected
PARSE.incorrect.unindent=Unindent does not match any outer indentation level.
PARSE.eof.docstring=Docstring at end of file does not precede any statement
PARSE.rule.expected.rule.commend.to.docstring=Expecting rule keyword, comment or docstrings inside a rule definition.
PARSE.use.with.not.allowed=Keyword 'with' is not allowed with rule pattern '*'
PARSE.use.double.mult.sign=Can't be '*' after '*' in the new rule name
PARSE.use.rule.keyword.expected='rule' keyword is expected after 'use'
PARSE.use.with.not.allowed=Keyword 'with' in 'use rule' statement is not allowed in combination with rule pattern '*'.
PARSE.use.double.mult.sign=Expecting rulename modifying pattern (e.g. modulename_*) after 'as' keyword
PARSE.use.requires.wildcard=Multiple rules in 'use rule' statement but name modification ('as' statement) does not contain a wildcard '*'.
PARSE.use.rule.keyword.expected=Expecting keyword 'rule' after keyword 'use'
PARSE.use.names.expected=Expecting '*', rule name, or rule listing (comma separated) after 'use rule' statement
PARSE.use.few.names.from.current.module='use rule' statement from rule in the same module must declare a single rule but multiple rules are declared.
PARSE.use.unexpected.names.separator=Unexpected token in comma separated list of rules within 'use rule' statement.
PARSE.use.wildcard.in.names.list=Wildcard '*' can't be used with rules names List
PARSE.use.unexpected.list.ending=Expecting list of rules in 'use rule' statement to end with keyword 'from'.
PARSE.use.expecting.module.name=Expecting module name after 'from' keyword in 'use rule' statement.
PARSE.use.with.missed=':' can be placed only after 'with' keyword, which is missed
PARSE.use.expecting.colon=Expecting colon after 'with' keyword in 'use rule' statement.
PARSE.use.args.sections.forbidden=Redeclaration of imported rules is forbidden for wildcard '*'
PARSE.use.as.or.with.expecting=Expecting either 'as', 'with' or end of line in 'use rule' statement.
PARSE.use.with.expecting=Expecting 'with:' at the end of 'use rule' declaration but before arguments sections


# String language parsing
SMKSL.PARSE.expected.identifier.name=Expected identifier name
Expand Down
66 changes: 0 additions & 66 deletions src/test/resources/features/highlighting/smk_parsing_error.feature

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,18 @@ Feature: Annotate additional syntax
"""
PY.KEYWORD
"""
Then I expect inspection info on <as> with message
"""
PY.KEYWORD
"""
Then I expect inspection info on <B> with message
"""
PY.FUNC_DEFINITION
"""
Then I expect inspection info on <with> with message
"""
PY.KEYWORD
"""
Then I expect inspection info on <input> with message
"""
PY.DECORATOR
Expand All @@ -228,6 +236,14 @@ Feature: Annotate additional syntax
"""
PY.KEYWORD
"""
Then I expect inspection info on <from> with message
"""
PY.KEYWORD
"""
Then I expect inspection info on <as> with message
"""
PY.KEYWORD
"""
Then I expect inspection info on <other_*> with message
"""
PY.FUNC_DEFINITION
Expand Down
9 changes: 8 additions & 1 deletion testData/psi/Use.smk
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ use rule f_z as x_z with:
use rule * from last_module1 as *_other
use rule * from last_module2 as other_*
use rule * from last_module3 as other_*_other
use rule * from last_module4
use rule * from last_module4
use rule a, b from m
use rule a,b,c from m as *_other with:

use rule rule from module as with:
input: "text"

use rule a as b with: output: "dataset"
Loading

0 comments on commit 0c79a6f

Please sign in to comment.