How to use linecol method in autotest

Best Python code snippet using autotest_python

jedibackend.py

Source:jedibackend.py Github

copy

Full Screen

...16 self.project_root = project_root17 self.completions = {}18 sys.path.append(project_root)19 def rpc_get_completions(self, filename, source, offset):20 line, column = pos_to_linecol(source, offset)21 proposals = run_with_debug(jedi, 'completions',22 source=source, line=line, column=column,23 path=filename, encoding='utf-8')24 if proposals is None:25 return []26 self.completions = dict((proposal.name, proposal)27 for proposal in proposals)28 return [{'name': proposal.name.rstrip("="),29 'suffix': proposal.complete.rstrip("="),30 'annotation': proposal.type,31 'meta': proposal.description}32 for proposal in proposals]33 def rpc_get_completion_docstring(self, completion):34 proposal = self.completions.get(completion)35 if proposal is None:36 return None37 else:38 return proposal.docstring(fast=False)39 def rpc_get_completion_location(self, completion):40 proposal = self.completions.get(completion)41 if proposal is None:42 return None43 else:44 return (proposal.module_path, proposal.line)45 def rpc_get_docstring(self, filename, source, offset):46 line, column = pos_to_linecol(source, offset)47 locations = run_with_debug(jedi, 'goto_definitions',48 source=source, line=line, column=column,49 path=filename, encoding='utf-8')50 if locations and locations[-1].docstring():51 return ('Documentation for {0}:\n\n'.format(52 locations[-1].full_name) + locations[-1].docstring())53 else:54 return None55 def rpc_get_definition(self, filename, source, offset):56 line, column = pos_to_linecol(source, offset)57 locations = run_with_debug(jedi, 'goto_definitions',58 source=source, line=line, column=column,59 path=filename, encoding='utf-8')60 # goto_definitions() can return silly stuff like __builtin__61 # for int variables, so we fall back on goto() in those62 # cases. See issue #76.63 if (64 locations and65 locations[0].module_path is None66 ):67 locations = run_with_debug(jedi, 'goto_assignments',68 source=source, line=line,69 column=column,70 path=filename, encoding='utf-8')71 if not locations:72 return None73 else:74 loc = locations[-1]75 try:76 if loc.module_path:77 if loc.module_path == filename:78 offset = linecol_to_pos(source,79 loc.line,80 loc.column)81 else:82 with open(loc.module_path) as f:83 offset = linecol_to_pos(f.read(),84 loc.line,85 loc.column)86 else:87 return None88 except IOError:89 return None90 return (loc.module_path, offset)91 def rpc_get_assignment(self, filename, source, offset):92 line, column = pos_to_linecol(source, offset)93 locations = run_with_debug(jedi, 'goto_assignments',94 source=source, line=line, column=column,95 path=filename, encoding='utf-8')96 if not locations:97 return None98 else:99 loc = locations[-1]100 try:101 if loc.module_path:102 if loc.module_path == filename:103 offset = linecol_to_pos(source,104 loc.line,105 loc.column)106 else:107 with open(loc.module_path) as f:108 offset = linecol_to_pos(f.read(),109 loc.line,110 loc.column)111 else:112 return None113 except IOError:114 return None115 return (loc.module_path, offset)116 def rpc_get_calltip(self, filename, source, offset):117 line, column = pos_to_linecol(source, offset)118 calls = run_with_debug(jedi, 'call_signatures',119 source=source, line=line, column=column,120 path=filename, encoding='utf-8')121 if calls:122 call = calls[0]123 else:124 call = None125 if not call:126 return None127 return {"name": call.name,128 "index": call.index,129 "params": [param.description for param in call.params]}130 def rpc_get_usages(self, filename, source, offset):131 """Return the uses of the symbol at offset.132 Returns a list of occurrences of the symbol, as dicts with the133 fields name, filename, and offset.134 """135 line, column = pos_to_linecol(source, offset)136 uses = run_with_debug(jedi, 'usages',137 source=source, line=line, column=column,138 path=filename, encoding='utf-8')139 if uses is None:140 return None141 result = []142 for use in uses:143 if use.module_path == filename:144 offset = linecol_to_pos(source, use.line, use.column)145 elif use.module_path is not None:146 with open(use.module_path) as f:147 text = f.read()148 offset = linecol_to_pos(text, use.line, use.column)149 result.append({"name": use.name,150 "filename": use.module_path,151 "offset": offset})152 return result153 def rpc_get_names(self, filename, source, offset):154 """Return the list of possible names"""155 names = jedi.api.names(source=source,156 path=filename, encoding='utf-8',157 all_scopes=True,158 definitions=True,159 references=True)160 result = []161 for name in names:162 if name.module_path == filename:163 offset = linecol_to_pos(source, name.line, name.column)164 elif name.module_path is not None:165 with open(name.module_path) as f:166 text = f.read()167 offset = linecol_to_pos(text, name.line, name.column)168 result.append({"name": name.name,169 "filename": name.module_path,170 "offset": offset})171 return result172# From the Jedi documentation:173#174# line is the current line you want to perform actions on (starting175# with line #1 as the first line). column represents the current176# column/indent of the cursor (starting with zero). source_path177# should be the path of your file in the file system.178def pos_to_linecol(text, pos):179 """Return a tuple of line and column for offset pos in text.180 Lines are one-based, columns zero-based.181 This is how Jedi wants it. Don't ask me why.182 """183 line_start = text.rfind("\n", 0, pos) + 1184 line = text.count("\n", 0, line_start) + 1185 col = pos - line_start186 return line, col187def linecol_to_pos(text, line, col):188 """Return the offset of this line and column in text.189 Lines are one-based, columns zero-based.190 This is how Jedi wants it. Don't ask me why.191 """192 nth_newline_offset = 0...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful