Skip to content

Commit

Permalink
Extract SymbolHelpers file
Browse files Browse the repository at this point in the history
  • Loading branch information
Gert-dev committed Oct 18, 2017
1 parent a0b4bef commit 241328a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
35 changes: 2 additions & 33 deletions lib/GotoDefinitionProvider.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{Range} = require 'atom'

LanguageClientUtils = require '../node_modules/atom-languageclient/build/lib/utils'
SymbolHelpers = require './SymbolHelpers'

module.exports =

Expand Down Expand Up @@ -30,7 +28,7 @@ class GotoDefinitionProvider
return null if not result?

return {
range : @getRangeForSymbolAtPosition(editor, bufferPosition)
range : SymbolHelpers.getRangeForSymbolAtPosition(editor, bufferPosition)

callback : () =>
atom.workspace.open(result.uri, {
Expand All @@ -43,32 +41,3 @@ class GotoDefinitionProvider
return null

return @service.gotoDefinitionAt(editor, bufferPosition).then(successHandler, failureHandler)

###*
* Slightly modified variant of the LanguageClientUtils getWordAtPosition.
*
* This variant does not treat the backslash as a non-word character, so it is not treated as boundary and the range
* does not stop when it is found. This is important for qualified names in PHP (i.e. imports, qualified function
* calls, ...).
*
* @param {TextEditor} editor
* @param {Point} position
*
* @see https://github.com/atom/atom-languageclient/blob/master/lib/utils.js
###
getRangeForSymbolAtPosition: (editor, position) ->
scopeDescriptor = editor.scopeDescriptorForBufferPosition(position)
nonWordCharacters = editor.getNonWordCharacters(scopeDescriptor)
nonWordCharacters = nonWordCharacters.replace("\\", '')
nonWordCharacters = LanguageClientUtils.escapeRegExp(nonWordCharacters)

range = LanguageClientUtils._getRegexpRangeAtPosition(
editor.getBuffer(),
position,
///^[\t ]*$|[^\s#{nonWordCharacters}]+///g
)

if range == null
return new Range(position, position);

return range
33 changes: 33 additions & 0 deletions lib/SymbolHelpers.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{Range} = require 'atom'

LanguageClientUtils = require '../node_modules/atom-languageclient/build/lib/utils'

module.exports =
###*
* Slightly modified variant of the LanguageClientUtils getWordAtPosition.
*
* This variant does not treat the backslash as a non-word character, so it is not treated as boundary and the range
* does not stop when it is found. This is important for qualified names in PHP (i.e. imports, qualified function
* calls, ...).
*
* @param {TextEditor} editor
* @param {Point} position
*
* @see https://github.com/atom/atom-languageclient/blob/master/lib/utils.js
###
getRangeForSymbolAtPosition: (editor, position) ->
scopeDescriptor = editor.scopeDescriptorForBufferPosition(position)
nonWordCharacters = editor.getNonWordCharacters(scopeDescriptor)
nonWordCharacters = nonWordCharacters.replace("\\", '')
nonWordCharacters = LanguageClientUtils.escapeRegExp(nonWordCharacters)

range = LanguageClientUtils._getRegexpRangeAtPosition(
editor.getBuffer(),
position,
///^[\t ]*$|[^\s#{nonWordCharacters}]+///g
)

if range == null
return new Range(position, position);

return range

0 comments on commit 241328a

Please sign in to comment.