auto-indent templates
when template are inserted, it should be indented (formatted) correctly.
Leave a comment
Updating tickets (#3255, #3262, #3271, #3277, #3279, #3287, #3313, #3317, #3318, #3320, #3329, #1000000, #1000002, #1000004, #1000005, #1000007, #1000011, #1000013, #1000018, #1000019, #1000020, #1000022, #1000023, #1000024, #1000025, #1000026, #1000028, #1000031, #1000033, #1000034, #1000037, #1000039, #1000040, #1000041, #1000057, #1000058, #1000060, #1000061, #1000063, #1000064, #1000065, #1000067, #1000070, #1000073, #1000076, #1000080, #1000082, #1000083, #1000084, #1000085, #1000087, #1000088, #1000089, #1000090, #1000092, #1000093, #1000094, #1000095, #1000097, #1000102, #1000104, #1000106, #1000108, #1000110, #1000111, #1000116, #1000124, #1000126, #1000127, #1000129, #1000132, #1000133, #1000136, #1000139, #1000143, #1000144, #1000145, #1000148, #1000149, #1000152, #1000154, #1000155, #1000157, #1000158, #1000159, #1000161, #1000169, #1000170, #1000172, #1000174, #1000176, #1000178, #1000179, #1000183, #1000185, #1000188, #1000189, #1000192, #1000196, #1000198)
on 2012-01-25 08:46 *
By skyluc
Version changed from 1.0.0-SNAPSHOT to 2.0.0-final-29
Eclipse version set to All
Assigned to changed from David Bernard to -none-
Milestone changed from Backlog to Enhancements
Permission type changed from None to Public
on 2013-05-14 05:47 *
By Iulian Dragos
Awesome!
(Note to self and anyone who is interested)
I had a look at creating some tests. The main problem seems to be that the API expects that we have access to various UI instances.
A rough sketch of what the test-code needs to do is (The final test code would obviously be much prettier and not use a hardcoded offset ;) )
But this throws a null-pointer exception somewhere inside of ScalaTemplateCompletionProcessor.computeCompletionProposals
It might work if we could get a proper instance of ISourceViewer and then create the context using :
But I'm not sure if we can get a real instance of ISourceViewer in a headless test
I had a look at creating some tests. The main problem seems to be that the API expects that we have access to various UI instances.
A rough sketch of what the test-code needs to do is (The final test code would obviously be much prettier and not use a hardcoded offset ;) )
val x1 = new TemplateCompletionProposalComputer
val document = new SynchronizableDocument
document.set("""class A {}""")
val context: ContentAssistInvocationContext = new ContentAssistInvocationContext(document, 10)
val props = x1.computeCompletionProposals(context, new NullProgressMonitor)
props.get(0).apply(document)
But this throws a null-pointer exception somewhere inside of ScalaTemplateCompletionProcessor.computeCompletionProposals
It might work if we could get a proper instance of ISourceViewer and then create the context using :
val viewer: ISourceViewer = ???
val context: ContentAssistInvocationContext = new ContentAssistInvocationContext(viewer, 10)
But I'm not sure if we can get a real instance of ISourceViewer in a headless test
Okay, so I played around with this some more. I don't think it's possible to write tets for this. The closest I got was this, but some assertion deep in the UI codes fails.
It's probably still possible to fix the bug but without being able to add tests it's not very rewarding.
val proposalComputer = new TemplateCompletionProposalComputer
val document = new Document("")
val viewer = mock(classOf[ISourceViewer])
val selectionProvider = mock(classOf[ISelectionProvider])
val selection = new TextSelection(document, 0, 0)
when(selectionProvider.getSelection()).thenReturn(selection)
when(viewer.getSelectionProvider()).thenReturn(selectionProvider)
when(viewer.getDocument()).thenReturn(document)
val context = new ContentAssistInvocationContext(viewer, 0)
val props = proposalComputer.computeCompletionProposals(context, new NullProgressMonitor)
val template = props.get(1)
template.asInstanceOf[TemplateProposal].apply(viewer, 0, 0, 0)
// template.apply(document) // this doesn't fail but it doesn't change the document either.
It's probably still possible to fix the bug but without being able to add tests it's not very rewarding.
on 2013-05-15 04:28 *
By Mirco Dotta
LGTM. Go for it :-)
on 2013-05-15 05:16 *
By Mirco Dotta
@mads379 Oh, sorry, I should have read your message more carefully. If there is no way to add a test that runs headless-ly, maybe you could add one that requires the UI so that we can run it inside Eclipse. I guess it still better than having no test at all.
on 2014-04-04 05:49 *
By Iulian Dragos
Assigned to set to Iulian Dragos
Status changed from Accepted to Fixed
Indent templates to the same indentation as the line of the insertion point.
Simple solution that makes templates usable: even if they are not properly indented,
multi-line templates now align to the first non-whitespace character of the insertion point.
No tests because this is purely UI code.
Fix #1000058, #1000626,
Branch: master
Commit: scala-ide:0431a8f8c8
Simple solution that makes templates usable: even if they are not properly indented,
multi-line templates now align to the first non-whitespace character of the insertion point.
No tests because this is purely UI code.
Fix #1000058, #1000626,
Branch: master
Commit: scala-ide:0431a8f8c8