From 86556ebfdbbd4b8e9edc9d3085ea21d6c0bae2e2 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 7 Sep 2018 01:53:09 +0200 Subject: compiler refactoring; use typesafe path handing; docgen: render symbols between modules --- nimsuggest/nimsuggest.nim | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'nimsuggest/nimsuggest.nim') diff --git a/nimsuggest/nimsuggest.nim b/nimsuggest/nimsuggest.nim index b20572b0e..34b1cc4f7 100644 --- a/nimsuggest/nimsuggest.nim +++ b/nimsuggest/nimsuggest.nim @@ -20,7 +20,8 @@ import compiler / [options, commands, modules, sem, passes, passaux, msgs, nimconf, extccomp, condsyms, sigmatch, ast, scriptconfig, - idents, modulegraphs, vm, prefixmatches, lineinfos, cmdlinehelper] + idents, modulegraphs, vm, prefixmatches, lineinfos, cmdlinehelper, + pathutils] when defined(windows): import winlean @@ -158,10 +159,11 @@ proc symFromInfo(graph: ModuleGraph; trackPos: TLineInfo): PSym = if m != nil and m.ast != nil: result = findNode(m.ast, trackPos) -proc execute(cmd: IdeCmd, file, dirtyfile: string, line, col: int; +proc execute(cmd: IdeCmd, file, dirtyfile: AbsoluteFile, line, col: int; graph: ModuleGraph) = let conf = graph.config - myLog("cmd: " & $cmd & ", file: " & file & ", dirtyFile: " & dirtyfile & + myLog("cmd: " & $cmd & ", file: " & file.string & + ", dirtyFile: " & dirtyfile.string & "[" & $line & ":" & $col & "]") conf.ideCmd = cmd if cmd == ideChk: @@ -175,8 +177,8 @@ proc execute(cmd: IdeCmd, file, dirtyfile: string, line, col: int; var isKnownFile = true let dirtyIdx = fileInfoIdx(conf, file, isKnownFile) - if dirtyfile.len != 0: msgs.setDirtyFile(conf, dirtyIdx, dirtyfile) - else: msgs.setDirtyFile(conf, dirtyIdx, "") + if not dirtyfile.isEmpty: msgs.setDirtyFile(conf, dirtyIdx, dirtyfile) + else: msgs.setDirtyFile(conf, dirtyIdx, AbsoluteFile"") conf.m.trackPos = newLineInfo(dirtyIdx, line, col) conf.m.trackPosAttached = false @@ -186,7 +188,7 @@ proc execute(cmd: IdeCmd, file, dirtyfile: string, line, col: int; if not isKnownFile: graph.compileProject() if conf.suggestVersion == 0 and conf.ideCmd in {ideUse, ideDus} and - dirtyfile.len == 0: + dirtyfile.isEmpty: discard "no need to recompile anything" else: let modIdx = graph.parentModule(dirtyIdx) @@ -204,12 +206,12 @@ proc execute(cmd: IdeCmd, file, dirtyfile: string, line, col: int; proc executeEpc(cmd: IdeCmd, args: SexpNode; graph: ModuleGraph) = let - file = args[0].getStr + file = AbsoluteFile args[0].getStr line = args[1].getNum column = args[2].getNum - var dirtyfile = "" + var dirtyfile = AbsoluteFile"" if len(args) > 3: - dirtyfile = args[3].getStr("") + dirtyfile = AbsoluteFile args[3].getStr("") execute(cmd, file, dirtyfile, int(line), int(column), graph) proc returnEpc(socket: Socket, uid: BiggestInt, s: SexpNode|string, @@ -431,11 +433,11 @@ proc execCmd(cmd: string; graph: ModuleGraph; cachedMsgs: CachedMsgs) = i += parseInt(cmd, col, i) if conf.ideCmd == ideKnown: - results.send(Suggest(section: ideKnown, quality: ord(fileInfoKnown(conf, orig)))) + results.send(Suggest(section: ideKnown, quality: ord(fileInfoKnown(conf, AbsoluteFile orig)))) else: if conf.ideCmd == ideChk: for cm in cachedMsgs: errorHook(conf, cm.info, cm.msg, cm.sev) - execute(conf.ideCmd, orig, dirtyfile, line, col, graph) + execute(conf.ideCmd, AbsoluteFile orig, AbsoluteFile dirtyfile, line, col, graph) sentinel() proc recompileFullProject(graph: ModuleGraph) = @@ -451,7 +453,7 @@ proc mainThread(graph: ModuleGraph) = let conf = graph.config if gLogging: for it in conf.searchPaths: - log(it) + log(it.string) proc wrHook(line: string) {.closure.} = if gMode == mepc: @@ -496,7 +498,7 @@ proc mainCommand(graph: ModuleGraph) = wantMainModule(conf) if not fileExists(conf.projectFull): - quit "cannot find file: " & conf.projectFull + quit "cannot find file: " & conf.projectFull.string add(conf.searchPaths, conf.libpath) @@ -518,9 +520,9 @@ proc mainCommand(graph: ModuleGraph) = of mtcp: createThread(inputThread, replTcp, (gPort, gAddress)) of mepc: createThread(inputThread, replEpc, (gPort, gAddress)) of mcmdsug: createThread(inputThread, replCmdline, - (gPort, "sug \"" & conf.projectFull & "\":" & gAddress)) + (gPort, "sug \"" & conf.projectFull.string & "\":" & gAddress)) of mcmdcon: createThread(inputThread, replCmdline, - (gPort, "con \"" & conf.projectFull & "\":" & gAddress)) + (gPort, "con \"" & conf.projectFull.string & "\":" & gAddress)) mainThread(graph) joinThread(inputThread) close(requests) @@ -602,11 +604,12 @@ proc handleCmdLine(cache: IdentCache; conf: ConfigRef) = if binaryPath == "": raise newException(IOError, "Cannot find Nim standard library: Nim compiler not in PATH") - conf.prefixDir = binaryPath.splitPath().head.parentDir() - if not dirExists(conf.prefixDir / "lib"): conf.prefixDir = "" + conf.prefixDir = AbsoluteDir binaryPath.splitPath().head.parentDir() + if not dirExists(conf.prefixDir / RelativeDir"lib"): + conf.prefixDir = AbsoluteDir"" #msgs.writelnHook = proc (line: string) = log(line) - myLog("START " & conf.projectFull) + myLog("START " & conf.projectFull.string) discard self.loadConfigsAndRunMainCommand(cache, conf) -- cgit 1.4.1-2-gfad0 84'>84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212