def idetool(win, cmd, filename, line, col, dirtyFile="", extra=""): trackType = " --track:" filePath = filename projFile = Utility.get_nimproject(win) if projFile is None: projFile = filename workingDir = os.path.dirname(projFile) if dirtyFile != "": trackType = " --trackDirty:" filePath = dirtyFile + "," + filePath if False: # TODO - use this when it's not broken in nim # Ensure IDE Tools service is running Idetools.ensure_service() # Call the service args = "idetools" \ + trackType \ + "\"" + filePath + "," + str(line) + "," + str(col) + "\" " \ + cmd + extra print(args) return Idetools.service.communicate(args + "\r\n") else: compiler = sublime.load_settings("nim.sublime-settings").get( "nim_compiler_executable") if compiler == None or compiler == "": return "" args = compiler + " --verbosity:0 idetools " \ + trackType \ + "\"" + filePath + "," + str(line) + "," + str(col) \ + "\" " + cmd + " \"" + projFile + "\"" + extra print(args) output = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=workingDir) result = "" temp = output.stdout.read() # Convert bytes to string result = temp.decode('utf-8') # print(output.stderr.read()) output.wait() return result
def idetool(win, cmd, filename, line, col, dirtyFile="", extra=""): trackType = " --track:" filePath = filename projFile = Utility.get_nimproject(win) if projFile is None: projFile = filename workingDir = os.path.dirname(projFile) if dirtyFile != "": trackType = " --trackDirty:" filePath = dirtyFile + "," + filePath if False: # TODO - use this when it's not broken in nimrod # Ensure IDE Tools service is running Idetools.ensure_service() # Call the service args = "idetools" \ + trackType \ + "\"" + filePath + "," + str(line) + "," + str(col) + "\" " \ + cmd + extra print(args) return Idetools.service.communicate(args + "\r\n") else: compiler = sublime.load_settings("nimrod.sublime-settings").get("nimrod_compiler_executable") if compiler == None or compiler == "": return "" args = compiler + " --verbosity:0 idetools " \ + trackType \ + "\"" + filePath + "," + str(line) + "," + str(col) \ + "\" " + cmd + " \"" + projFile + "\"" + extra print(args) output = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=workingDir) result = "" temp = output.stdout.read() # Convert bytes to string result = temp.decode('utf-8') # print(output.stderr.read()) output.wait() return result
def idetool(win, cmd, filename, line, col, dirtyFile=""): filePath = filename projFile = Utility.get_nimproject(win) if projFile is None: projFile = filename if dirtyFile != "": filePath = filePath + '";"' + dirtyFile # Ensure IDE Tools server is running Idetools.ensure_service(projFile) # Call the server args = 'def "' + filePath + '":' + str(line) + ":" + str(col) print(args) # Write to service & read result result = Idetools.sendrecv(args) if result is not None: return result
def on_query_completions(self, view, prefix, locations): filename = view.file_name() if filename == None or not filename.endswith( ".nim") or not do_suggestions: return [] projFile = Utility.get_nimproject(view.window()) if projFile is None: projFile = filename modfilename = os.path.basename(filename) currentModule = modfilename[:-4] window = sublime.active_window() results = [] # Extract the cursor position pos = view.rowcol(view.sel()[0].begin()) line = pos[0] + 1 col = pos[1] suggestion_pos = position_str(filename, line, col) global had_suggestions global give_suggestions global last_suggestion_pos #print(suggestion_pos) #print(last_suggestion_pos) #print("had: " + str(had_suggestions)) #print("give: " + str(give_suggestions)) if (not give_suggestions and suggestion_pos != last_suggestion_pos): # Reset logic had_suggestions = False give_suggestions = False provide_suggestions = provide_immediate_completions or give_suggestions if not provide_suggestions: return [] last_suggestion_pos = suggestion_pos had_suggestions = True give_suggestions = False dirtyFileName = "" dirtyFile = None compiler = settings.get("nim_compiler_executable") if compiler == None or compiler == "": return [] pargs = compiler + " --verbosity:0 idetools " if view.is_dirty(): #Generate dirty file size = view.size() dirtyFile = tempfile.NamedTemporaryFile(suffix=".nim", delete=False) dirtyFileName = dirtyFile.name dirtyFile.file.write( view.substr(sublime.Region(0, size)).encode("UTF-8")) dirtyFile.file.close() pargs = pargs + "--trackDirty:" + dirtyFileName + "," else: pargs = pargs + "--track:" pargs = pargs + filename \ + "," + str(line) + "," + str(col) \ + " --suggest " + projFile print(pargs) handle = os.popen(pargs) line = " " while line: line = handle.readline() print(line) parts = line.split("\t") partlen = len(parts) if partlen != 8 or (parts[0] != "sug" and parts[0] != "con"): continue item = SuggestItem() item.symType = parts[1] item.qualName = parts[2] item.signature = parts[3] item.file = parts[4] item.line = int(parts[5]) item.col = int(parts[6]) item.docs = parts[7] dots = item.qualName.split(".") if len(dots) == 2: item.name = dots[1] item.modName = dots[0] else: item.modName = currentModule item.name = item.qualName item.prettify_signature(currentModule) completion = "" hint = "" if item.modName == currentModule: completion = item.name hint = item.name + "\t" + item.signature else: if prefix == "": completion = item.name hint = item.name + "\t" + item.signature else: completion = item.qualName hint = item.qualName + "\t" + item.signature results.append((hint, completion)) # Close the idetools connection handle.close() # Delete the dirty file if dirtyFile != None: dirtyFile.close() try: os.unlink(dirtyFile.name) except OSError: pass # get results from each tab return results # sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS
def on_query_completions(self, view, prefix, locations): filename = view.file_name() if filename == None or not filename.endswith(".nim") or not do_suggestions: return [] projFile = Utility.get_nimproject(view.window()) if projFile is None: projFile = filename modfilename = os.path.basename(filename) currentModule = modfilename[:-4] window = sublime.active_window() results = [] # Extract the cursor position pos = view.rowcol(view.sel()[0].begin()) line = pos[0] + 1 col = pos[1] suggestion_pos = position_str(filename, line, col) global had_suggestions global give_suggestions global last_suggestion_pos #print(suggestion_pos) #print(last_suggestion_pos) #print("had: " + str(had_suggestions)) #print("give: " + str(give_suggestions)) if (not give_suggestions and suggestion_pos != last_suggestion_pos): # Reset logic had_suggestions = False give_suggestions = False provide_suggestions = provide_immediate_completions or give_suggestions if not provide_suggestions: return [] last_suggestion_pos = suggestion_pos had_suggestions = True give_suggestions = False dirtyFileName = "" dirtyFile = None compiler = settings.get("nim_compiler_executable") if compiler == None or compiler == "": return [] pargs = compiler + " --verbosity:0 idetools " if view.is_dirty(): #Generate dirty file size = view.size() dirtyFile = tempfile.NamedTemporaryFile(suffix=".nim", delete=False) dirtyFileName = dirtyFile.name dirtyFile.file.write( view.substr(sublime.Region(0, size)).encode("UTF-8") ) dirtyFile.file.close() pargs = pargs + "--trackDirty:" + dirtyFileName + "," else: pargs = pargs + "--track:" pargs = pargs + filename \ + "," + str(line) + "," + str(col) \ + " --suggest " + projFile print(pargs) handle = os.popen(pargs) line = " " while line: line = handle.readline() print(line) parts = line.split("\t") partlen = len(parts) if partlen != 8 or (parts[0] != "sug" and parts[0] != "con"): continue item = SuggestItem() item.symType = parts[1] item.qualName = parts[2] item.signature = parts[3] item.file = parts[4] item.line = int(parts[5]) item.col = int(parts[6]) item.docs = parts[7] dots = item.qualName.split(".") if len(dots) == 2: item.name = dots[1] item.modName = dots[0] else: item.modName = currentModule item.name = item.qualName item.prettify_signature(currentModule) completion = "" hint = "" if item.modName == currentModule: completion = item.name hint = item.name + "\t" + item.signature else: if prefix == "": completion = item.name hint = item.name + "\t" + item.signature else: completion = item.qualName hint = item.qualName + "\t" + item.signature results.append((hint, completion)) # Close the idetools connection handle.close() # Delete the dirty file if dirtyFile != None: dirtyFile.close() try: os.unlink(dirtyFile.name) except OSError: pass # get results from each tab return results # sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS