Principled Syntactic Code Completion with Placeholders
-
Upload
eduardoufv -
Category
Education
-
view
113 -
download
4
Transcript of Principled Syntactic Code Completion with Placeholders
Principled Syntactic Code Completion using Placeholders
SLE’16 - Amsterdam
Sebastian Erdweg, Guido Wachsmuth, Eelco VisserEduardo Souza
3
*S. Amann, S. Proksch, S. Nadi, and M. Mezini. A study of visual studio usage in practice. In SANER, 2016.
10
Incomplete
!
Completeness: any program should be derivable through code completion.
Problems
Unsound!
13
Language Specification
Syntax Definition
Name Binding
Type Constraints
Code Completion
Syntactic Completion
Semantic Completion
Textual/Projectional IDE
Language Workbenches
17
Language Specification
SyntaxDefinition
Name Binding
Type Constraints
Code Completion
SyntacticCompletion
Semantic Completion
Textual IDE
Sound!
Complete!
Language Workbenches
18
Language Specification
SDF3 Name Binding
Type Constraints
Code Completion
SyntacticCompletion
Semantic Completion
Textual IDE
Sound!
Complete!
27
Deriving Syntactic Completion from the Syntax Definition
context-free syntax
Statement ::= "if" "(" Exp ")" Statement "else" Statement {"If"}
28
context-free syntax // placeholder rule
Statement ::= “$Statement" {“Statement-Plhdr"}
context-free syntax //regular production rule
Statement ::= "if" "(" Exp ")" Statement "else" Statement {"If"}
Make placeholders part of the language
Stm-Plhdr
If
Exp-Plhdr Stm-Plhdr
29
Stm-Plhdr
context-free syntax //regular production rule
Statement ::= "if" "(" Exp ")" Statement "else" Statement {"If"}
signature constructors // AST signatures
If : Exp * Statement * Statement -> Statement
Calculate placeholder expansions
30
rules rewrite-placeholder: Statement-Plhdr() -> If(Exp-Plhdr(), Statement-Plhdr(), Statement-Plhdr())
Format Expansions
context-free syntax
Statement ::= "if" "(" Exp ")" Statement "else" Statement {cons("If")}
context-free syntax // placeholder rule
Statement ::= "$Statement"Parse Placeholders
Expand Placeholders
Incompleteprograms
Completeprograms
Expand placeholder
Expand/overwrite placeholders
Correctprograms
31
Optional Parent
List of Statements
38
Add Element to List
Add Optional Element
Placeholder Inference
Optional Parent
List of Statements
Add Optional Element
39
No source region
Add first or last element
Placeholder Inference
Add Element to List
44
Placeholder Inference - Lists
[…]
[…]
Method
Cons
VarDecl
AssignInt “x”
VarRef
“x”
Add
Int
21
Cons
Nil
{ return[…]
int ;
Int
=
21
45
Placeholder Inference - Lists
[…]
[…]
Method
Cons
VarDecl
AssignInt “x”
VarRef
“x”
Add
Int
21
Cons
Nil
{ return[…]
int ;
Int
=
21
46
Placeholder Inference - Lists
[…]
[…]
Method
Cons
VarDecl
AssignInt “x”
VarRef
“x”
Add
Int
21
Cons
Nil
{ return[…]
int ;
Int
=
21
47
Placeholder Inference - Lists
[…]
[…]
Method
Cons
VarDecl
AssignInt “x”
VarRef
“x”
Add
Int
21
Cons
Nil
{ return[…]
int ;
Int
=
21
49
Incompleteprograms
Completeprograms
Expand placeholder
Infer placeholder
Correctprograms
Infer placeholder
Expand/overwrite placeholders
54
context-free syntax //regular syntax rules
Statement.VarDecl = <<Type> <ID>;> Statement.Assign = <<VarRef> = <Exp>;>
Insertion Rules
// derived insertion rules for placeholderscontext-free syntax
Type.Type-Plhdr = {symbol-insertion} ID.ID-Plhdr = {symbol-insertion} Statement.Statement-Plhdr = {symbol-insertion} VarRef.VarRef-Plhdr = {symbol-insertion} Exp.Exp-Plhdr = {symbol-insertion}
// derived insertion rules for literalslexical syntax
"=" = {symbol-completion} ";" = {symbol-completion}
55
Proposal nodes
Insertion nodes
[…]
[…]
Stmt*
amb
VarDecl
ClassType
“x”
VarDecl
[…]
Assign
ID-Plhdr ;
Assign
VarRef
“x”
Exp-Plhdr ;=
Apply insertion rules at the cursor
56
Limit the search space!
Exp-Plhdr Exp-Plhdr+
Assign
VarRef
“x”
;=
[…]
Add
Assign
VarRef
“x”
;=
[…]
Exp-Plhdr
57
Greedy recovery!
[…]
[…]
Stmt*
amb
VarDecl
ClassType
“x”
VarDecl
[…]
Assign
ID-Plhdr ;
Assign
VarRef
“x”
Exp-Plhdr ;=
Incorrectprograms
Incompleteprograms
Completeprograms
Expand placeholder
Correctprograms
Expand/overwrite placeholders
61
Incorrectprograms
Incompleteprograms
Completeprograms
Expand placeholder
Infer placeholder
Correctprograms
Infer placeholder
Expand/overwrite placeholders
62
Incorrectprograms
Incompleteprograms
Completeprograms
Expand placeholder
Infer placeholder
Correctprograms
Infer placeholder
Expand/overwrite placeholders
Recover incomplete
program
Recover completeprogram
63