summary refs log tree commit diff stats
path: root/compiler/nimfix/pretty.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/nimfix/pretty.nim')
-rw-r--r--compiler/nimfix/pretty.nim33
1 files changed, 17 insertions, 16 deletions
diff --git a/compiler/nimfix/pretty.nim b/compiler/nimfix/pretty.nim
index 8ba922927..96429ad53 100644
--- a/compiler/nimfix/pretty.nim
+++ b/compiler/nimfix/pretty.nim
@@ -13,8 +13,9 @@
 import
   strutils, os, intsets, strtabs
 
-import compiler/options, compiler/ast, compiler/astalgo, compiler/msgs,
-  compiler/semdata, compiler/nimfix/prettybase, compiler/ropes, compiler/idents
+import ".." / [options, ast, astalgo, msgs, semdata, ropes, idents,
+  configuration]
+import prettybase
 
 type
   StyleCheck* {.pure.} = enum None, Warn, Auto
@@ -24,11 +25,11 @@ var
   gStyleCheck*: StyleCheck
   gCheckExtern*, gOnlyMainfile*: bool
 
-proc overwriteFiles*() =
-  let doStrip = options.getConfigVar("pretty.strip").normalize == "on"
+proc overwriteFiles*(conf: ConfigRef) =
+  let doStrip = options.getConfigVar(conf, "pretty.strip").normalize == "on"
   for i in 0 .. high(gSourceFiles):
     if gSourceFiles[i].dirty and not gSourceFiles[i].isNimfixFile and
-        (not gOnlyMainfile or gSourceFiles[i].fileIdx == gProjectMainIdx):
+        (not gOnlyMainfile or gSourceFiles[i].fileIdx == conf.projectMainIdx.FileIndex):
       let newFile = if gOverWrite: gSourceFiles[i].fullpath
                     else: gSourceFiles[i].fullpath.changeFileExt(".pretty.nim")
       try:
@@ -41,7 +42,7 @@ proc overwriteFiles*() =
           f.write(gSourceFiles[i].newline)
         f.close
       except IOError:
-        rawMessage(errCannotOpenFile, newFile)
+        rawMessage(conf, errGenerated, "cannot open file: " & newFile)
 
 proc `=~`(s: string, a: openArray[string]): bool =
   for x in a:
@@ -95,7 +96,7 @@ proc beautifyName(s: string, k: TSymKind): string =
 proc replaceInFile(info: TLineInfo; newName: string) =
   loadFile(info)
 
-  let line = gSourceFiles[info.fileIndex].lines[info.line-1]
+  let line = gSourceFiles[info.fileIndex.int].lines[info.line.int-1]
   var first = min(info.col.int, line.len)
   if first < 0: return
   #inc first, skipIgnoreCase(line, "proc ", first)
@@ -107,28 +108,28 @@ proc replaceInFile(info: TLineInfo; newName: string) =
   if differ(line, first, last, newName):
     # last-first+1 != newName.len or
     var x = line.substr(0, first-1) & newName & line.substr(last+1)
-    system.shallowCopy(gSourceFiles[info.fileIndex].lines[info.line-1], x)
-    gSourceFiles[info.fileIndex].dirty = true
+    system.shallowCopy(gSourceFiles[info.fileIndex.int].lines[info.line.int-1], x)
+    gSourceFiles[info.fileIndex.int].dirty = true
 
-proc checkStyle(info: TLineInfo, s: string, k: TSymKind; sym: PSym) =
+proc checkStyle(conf: ConfigRef; info: TLineInfo, s: string, k: TSymKind; sym: PSym) =
   let beau = beautifyName(s, k)
   if s != beau:
     if gStyleCheck == StyleCheck.Auto:
       sym.name = getIdent(beau)
       replaceInFile(info, beau)
     else:
-      message(info, hintName, beau)
+      message(conf, info, hintName, beau)
 
-proc styleCheckDefImpl(info: TLineInfo; s: PSym; k: TSymKind) =
+proc styleCheckDefImpl(conf: ConfigRef; info: TLineInfo; s: PSym; k: TSymKind) =
   # operators stay as they are:
   if k in {skResult, skTemp} or s.name.s[0] notin prettybase.Letters: return
   if k in {skType, skGenericParam} and sfAnon in s.flags: return
   if {sfImportc, sfExportc} * s.flags == {} or gCheckExtern:
-    checkStyle(info, s.name.s, k, s)
+    checkStyle(conf, info, s.name.s, k, s)
 
 template styleCheckDef*(info: TLineInfo; s: PSym; k: TSymKind) =
   when defined(nimfix):
-    if gStyleCheck != StyleCheck.None: styleCheckDefImpl(info, s, k)
+    if gStyleCheck != StyleCheck.None: styleCheckDefImpl(conf, info, s, k)
 
 template styleCheckDef*(info: TLineInfo; s: PSym) =
   styleCheckDef(info, s, s.kind)
@@ -136,7 +137,7 @@ template styleCheckDef*(s: PSym) =
   styleCheckDef(s.info, s, s.kind)
 
 proc styleCheckUseImpl(info: TLineInfo; s: PSym) =
-  if info.fileIndex < 0: return
+  if info.fileIndex.int < 0: return
   # we simply convert it to what it looks like in the definition
   # for consistency
 
@@ -151,4 +152,4 @@ proc styleCheckUseImpl(info: TLineInfo; s: PSym) =
 
 template styleCheckUse*(info: TLineInfo; s: PSym) =
   when defined(nimfix):
-    if gStyleCheck != StyleCheck.None: styleCheckUseImpl(info, s)
+    if gStyleCheck != StyleCheck.None: styleCheckUseImpl(conf, info, s)