Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 438892

Summary: ContentAssist#getPrefixStart should compute based on whitespace boundries
Product: [ECD] Orion Reporter: Michael Rennie <Michael_Rennie>
Component: EditorAssignee: Michael Rennie <Michael_Rennie>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: mamacdon
Version: unspecified   
Target Milestone: 7.0   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 442395    
Attachments:
Description Flags
proposed fix none

Description Michael Rennie CLA 2014-07-03 23:49:50 EDT
While trying to add content assist template support for JSDoc I kept finding that the prefixes and offsets were always wrong.

For a snippet like:

/**
 * @description Object of error types
 * @since 7.0 
 * @re^<- activate content assist here
 */
var ErrorTypes = {

The prefix would be 're' which of course would insert a bad completion. Even after fixing (hack) the prefix, the linked mode for the template would be off by one - the '@' I had to 'fix'.

The problem is in the regex in ContentAssist#getPrefixStart:

while (index > 0 && /[A-Za-z0-9_]/.test(model.getText(index - 1, index))) {

it should match anything not a whitespace char.

This fixes the problem:

/\S/i.test(model.getText(index - 1, index))

unless there is some special reason I am missing that the assist prefix needs to be so restrictive...
Comment 1 Michael Rennie CLA 2014-07-04 00:12:46 EDT
(In reply to Michael Rennie from comment #0)

> This fixes the problem:
> 
> /\S/i.test(model.getText(index - 1, index))
> 
> unless there is some special reason I am missing that the assist prefix
> needs to be so restrictive...

But...it introduces a problem with our JS content assist for 'this.'.

Perhaps there just needs to be a way to have the client report at what prefix the insertion should start? Rather than again calling getPrefixStart.
Comment 2 Mark Macdonald CLA 2014-07-29 16:39:01 EDT
Yeah, it would be convenient if a content assist provider could just provide a regex that the engine should use to figure out the prefix instead of assuming [A-Za-z0-9_] all the time.
Comment 3 Michael Rennie CLA 2014-08-22 15:43:27 EDT
Created attachment 246270 [details]
proposed fix

Perhaps a better idea would be to leave all the default stuff as-is and allow providers to tag their proposals with the prefix used. If the prefix exists on the proposal its used, otherwise the default (current computation) is used.
Comment 4 Michael Rennie CLA 2014-08-22 16:20:07 EDT
Slienio noticed I was not correctly resetting the default prefix in the patch, I pushed the updated fix to master:

http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=7203944d2468ca44c6a329bd60f2f710db26497d