Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 239837 Details for
Bug 427931
Odd marking of occurrences
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
fix
occurrences-with-tokens.patch (text/plain), 12.63 KB, created by
Michael Rennie
on 2014-02-11 16:26:24 EST
(
hide
)
Description:
fix
Filename:
MIME Type:
Creator:
Michael Rennie
Created:
2014-02-11 16:26:24 EST
Size:
12.63 KB
patch
obsolete
>diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/finder.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/finder.js >index 665a22e..92ce1c8 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/finder.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/finder.js >@@ -110,10 +110,12 @@ > idx = 0; > token = tokens[0]; > if(offset >= token.range[0] && offset < token.range[1]) { >+ token.index = offset; > return token; > } > token = tokens[max]; >- if(offset >= token.range[0] && offset < token.range[1]) { >+ if(offset >= token.range[0]) { >+ token.index = max; > return token; > } > token = null; >@@ -123,14 +125,30 @@ > if(offset < token.range[0]) { > max = idx-1; > } >- else if(offset >= token.range[1]) { >+ else if(offset > token.range[1]) { > min = idx+1; > } >+ else if(offset === token.range[1]) { >+ var next = tokens[idx+1]; >+ if(next.range[0] === token.range[1]) { >+ min = idx+1; >+ } >+ else { >+ token.index = idx; >+ return token; >+ } >+ } > else if(offset >= token.range[0] && offset < token.range[1]) { >+ token.index = idx; > return token; > } > if(min === max) { >- return tokens[min]; >+ token = tokens[min]; >+ if(offset >= token.range[0] && offset <= token.range[1]) { >+ token.index = min; >+ return token; >+ } >+ return null; > } > } > } >diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/occurrences.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/occurrences.js >index ab0dbf9..80fac56 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/occurrences.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/occurrences.js >@@ -42,6 +42,7 @@ > * @returns The status if we should continue visiting > */ > enter: function(node) { >+ var len, idx; > switch(node.type) { > case Estraverse.Syntax.Program: > this.occurrences = []; >@@ -54,8 +55,9 @@ > //we want the parent scope for a declaration, otherwise we leave it right away > this._enterScope(node); > if (node.params) { >- for (var i = 0; i < node.params.length; i++) { >- if(this.checkId(node.params[i], true)) { >+ len = node.params.length; >+ for (idx = 0; idx < len; idx++) { >+ if(this.checkId(node.params[idx], true)) { > return Estraverse.VisitorOption.Skip; > } > } >@@ -66,8 +68,9 @@ > if(this._enterScope(node)) { > return Estraverse.VisitorOption.Skip; > } >- for (var j = 0; j < node.params.length; j++) { >- if(this.checkId(node.params[j], true)) { >+ len = node.params.length; >+ for (idx = 0; idx < len; idx++) { >+ if(this.checkId(node.params[idx], true)) { > return Estraverse.VisitorOption.Skip; > } > } >@@ -79,8 +82,9 @@ > break; > case Estraverse.Syntax.ArrayExpression: > if (node.elements) { >- for (var k = 0; k < node.elements.length; k++) { >- this.checkId(node.elements[k]); >+ len = node.elements.length; >+ for (idx = 0; idx < len; idx++) { >+ this.checkId(node.elements[idx]); > } > } > break; >@@ -114,8 +118,9 @@ > case Estraverse.Syntax.CallExpression: > this.checkId(node.callee, false); > if (node.arguments) { >- for (var l = 0; l < node.arguments.length; l++) { >- this.checkId(node.arguments[l]); >+ len = node.arguments.length; >+ for (idx = 0; idx < len; idx++) { >+ this.checkId(node.arguments[idx]); > } > } > break; >@@ -127,9 +132,9 @@ > return Estraverse.VisitorOption.Skip; > } > if(node.properties) { >- var len = node.properties.length; >- for (var m = 0; m < len; m++) { >- var prop = node.properties[m]; >+ len = node.properties.length; >+ for (idx = 0; idx < len; idx++) { >+ var prop = node.properties[idx]; > if(this.thisCheck && prop.value && prop.value.type === Estraverse.Syntax.FunctionExpression) { > //tag it > prop.value.isprop = true; >@@ -145,9 +150,9 @@ > case Estraverse.Syntax.NewExpression: > this.checkId(node.callee, false); > if(node.arguments) { >- var len = node.arguments.length; >- for(var m = 0; m < len; m++) { >- this.checkId(node.arguments[m]); >+ len = node.arguments.length; >+ for(idx = 0; idx < len; idx++) { >+ this.checkId(node.arguments[idx]); > } > } > break; >@@ -163,7 +168,7 @@ > end: node.range[1] > }); > // if this node is the selected this we are in the right scope >- if (node.range[0] === this.context.node.range[0]){ >+ if (node.range[0] === this.context.token.range[0]){ > this.defscope = scope; > } > } >@@ -343,7 +348,7 @@ > this.visitor.enter = this.visitor.enter.bind(this.visitor); > this.visitor.leave = this.visitor.leave.bind(this.visitor); > } >- this.visitor.thisCheck = context.node && context.node.type === Estraverse.Syntax.ThisExpression; >+ this.visitor.thisCheck = context.token && context.token.type === 'Keyword' && context.token.value === 'this'; > this.visitor.context = context; > return this.visitor; > }, >@@ -352,13 +357,13 @@ > * @description Computes the node name to use while searching > * @function > * @private >- * @param {Object} node The AST node >+ * @param {Object} token The AST token > * @returns {String} The node name to use while seraching > */ >- _nameFromNode: function(node) { >- switch(node.type) { >- case Estraverse.Syntax.Identifier: return node.name; >- case Estraverse.Syntax.ThisExpression: return 'this'; >+ _nameFromNode: function(token) { >+ switch(token.type) { >+ case Estraverse.Syntax.Identifier: return token.value; >+ case 'Keyword': return 'this'; > } > }, > >@@ -367,19 +372,52 @@ > * @function > * @private > * @param {Object} context The selection context from the editor >- * @param {Object} node The AST node >+ * @param {Object} token The AST token > * @param {Object} ast The AST > * @returns {Boolean} True if we shoud skip computing occurrences > */ >- _skip: function(context, node, ast) { >- if(!node || node.type === Estraverse.Syntax.Literal) { >- return true; >- } >- var comment = Finder.findComment(context.selection.start, ast); >- if(comment) { >+ _skip: function(context, token, ast) { >+ if(!token) { > return true; > } >- return false; >+ if(token.type === 'Keyword') { >+ return token.value !== 'this'; >+ } >+ return token.type !== Estraverse.Syntax.Identifier >+ }, >+ >+ /** >+ * @description Gets the token from the given offset or the proceeding token if the found token >+ * is a punctuator >+ * @function >+ * @private >+ * @param {Number} offset The offset into the source >+ * @param {Object} ast The AST >+ * @return {Object} The token for the given offset or null >+ */ >+ _getToken: function(offset, ast) { >+ if(ast.tokens && ast.tokens.length > 0) { >+ var token = Finder.findToken(offset, ast.tokens); >+ if(token) { >+ if(token.type === 'Punctuator') { >+ var index = token.index; >+ //only check back if we are at the start of the punctuator i.e. here -> { >+ if(offset === token.range[0] && index != null && index > 0) { >+ var prev = ast.tokens[index-1]; >+ if(prev.range[1] !== token.range[0]) { >+ return null; >+ } >+ else { >+ token = prev; >+ } >+ } >+ } >+ if(token.type === 'Identifier' || (token.type === 'Keyword' && token.value === 'this')) { >+ return token; >+ } >+ } >+ } >+ return null; > }, > > /** >@@ -395,13 +433,13 @@ > var that = this; > return this.astManager.getAST(editorContext).then(function(ast) { > if(ast) { >- var node = Finder.findNode(ctxt.selection.start, ast); >- if(!that._skip(ctxt, node, ast)) { >+ var token = that._getToken(ctxt.selection.start, ast); >+ if(!that._skip(ctxt, token, ast)) { > var context = { > start: ctxt.selection.start, > end: ctxt.selection.end, >- word: that._nameFromNode(node), >- node: node, >+ word: that._nameFromNode(token), >+ token: token, > }; > var visitor = that.getVisitor(context); > Estraverse.traverse(ast, visitor); >diff --git a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/finderTests.js b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/finderTests.js >index 59e4371..3a9fd75 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/finderTests.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/finderTests.js >@@ -570,6 +570,148 @@ > }, > > /** >+ * Find a token in an AST with copious whitespace >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427931 >+ */ >+ test_findToken16: function() { >+ var text = "var foo = {f: function() {}}"; >+ return astManager.getAST(setUp(text)).then(function(ast) { >+ try { >+ var token = Finder.findToken(4, ast.tokens); >+ Assert.equal(null, token, 'Should not have found a token'); >+ } >+ finally { >+ astManager.updated(); >+ } >+ }); >+ }, >+ >+ /** >+ * Find a token in an AST with copious whitespace >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427931 >+ */ >+ test_findToken17: function() { >+ var text = "var foo = {f: function() {}}"; >+ return astManager.getAST(setUp(text)).then(function(ast) { >+ try { >+ var token = Finder.findToken(5, ast.tokens); >+ Assert.equal(null, token, 'Should not have found a token'); >+ } >+ finally { >+ astManager.updated(); >+ } >+ }); >+ }, >+ >+ /** >+ * Find a token in an AST with copious whitespace >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427931 >+ */ >+ test_findToken18: function() { >+ var text = "var foo = { f: function() {}}"; >+ return astManager.getAST(setUp(text)).then(function(ast) { >+ try { >+ var token = Finder.findToken(12, ast.tokens); >+ Assert.equal(null, token, 'Should not have found a token'); >+ } >+ finally { >+ astManager.updated(); >+ } >+ }); >+ }, >+ >+ /** >+ * Find a token in an AST with copious whitespace >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427931 >+ */ >+ test_findToken19: function() { >+ var text = "var foo = {f: function() {}}"; >+ return astManager.getAST(setUp(text)).then(function(ast) { >+ try { >+ var token = Finder.findToken(14, ast.tokens); >+ Assert.equal(null, token, 'Should not have found a token'); >+ } >+ finally { >+ astManager.updated(); >+ } >+ }); >+ }, >+ >+ /** >+ * Find a token in an AST with copious whitespace >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427931 >+ */ >+ test_findToken20: function() { >+ var text = "var foo = {f: function() {}}"; >+ return astManager.getAST(setUp(text)).then(function(ast) { >+ try { >+ var token = Finder.findToken(15, ast.tokens); >+ Assert.equal(null, token, 'Should not have found a token'); >+ } >+ finally { >+ astManager.updated(); >+ } >+ }); >+ }, >+ >+ /** >+ * Find a token in an AST with copious whitespace >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427931 >+ */ >+ test_findToken21: function() { >+ var text = " var foo = {f: function() {}}"; >+ return astManager.getAST(setUp(text)).then(function(ast) { >+ try { >+ var token = Finder.findToken(1, ast.tokens); >+ Assert.equal(null, token, 'Should not have found a token'); >+ } >+ finally { >+ astManager.updated(); >+ } >+ }); >+ }, >+ >+ /** >+ * Find a token in an AST with copious whitespace >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427931 >+ */ >+ test_findToken22: function() { >+ var text = " var foo = {f: function() {}}"; >+ return astManager.getAST(setUp(text)).then(function(ast) { >+ try { >+ var token = Finder.findToken(0, ast.tokens); >+ Assert.equal(null, token, 'Should not have found a token'); >+ } >+ finally { >+ astManager.updated(); >+ } >+ }); >+ }, >+ >+ /** >+ * Find a token in an AST with copious whitespace >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427931 >+ */ >+ test_findToken23: function() { >+ var text = "function f3( foo , bar , baz) {};"; >+ return astManager.getAST(setUp(text)).then(function(ast) { >+ try { >+ var token = Finder.findToken(17, ast.tokens); >+ if(!token) { >+ Assert.fail('Should have found a token'); >+ } >+ else { >+ Assert.equal(token.type, 'Identifier', 'Should have found an Identifier token'); >+ Assert.equal(token.value, 'foo', 'Should have found a foo token'); >+ } >+ } >+ finally { >+ astManager.updated(); >+ } >+ }); >+ }, >+ >+ /** > * Find a comment > * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426033 > */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 427931
: 239837