File tree 1 file changed +7
-8
lines changed
1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change 3
3
import re
4
4
import sys
5
5
import tokenize
6
- from io import BytesIO
6
+ from io import StringIO
7
7
from concurrent .futures import ThreadPoolExecutor
8
8
import importmagic
9
9
from pyls import hookimpl , lsp , _utils
@@ -66,12 +66,11 @@ def _get_imports_list(source, index=None):
66
66
67
67
def _tokenize (source ):
68
68
"""Tokenize python source code.
69
+ Returns only NAME tokens.
69
70
"""
70
- stream = BytesIO (source .encode ())
71
- tokens = tokenize .tokenize (stream .readline )
72
- if tokens is None :
73
- return []
74
- return list (tokens )
71
+ readline = StringIO (source ).readline
72
+ filter_name = lambda token : token [0 ] == tokenize .NAME
73
+ return filter (filter_name , tokenize .tokenize (readline ))
75
74
76
75
77
76
def _search_symbol (source , symbol ):
@@ -94,8 +93,8 @@ def _search_symbol(source, symbol):
94
93
}
95
94
}
96
95
"""
97
- symbol_tokens = _tokenize (symbol )
98
- source_tokens = _tokenize (source )
96
+ symbol_tokens = list ( _tokenize (symbol ) )
97
+ source_tokens = list ( _tokenize (source ) )
99
98
100
99
get_str = lambda token : token [1 ]
101
100
symbol_tokens_str = list (map (get_str , symbol_tokens ))
You can’t perform that action at this time.
0 commit comments