fix #8871 runnableExamples now preserves source code comments, litterals, and all formatting; other bug fix (#14439)
* fix #8871 runnableExamples now preserves source code comments, litterals, and all formatting * remove orig deadcode from getAllRunnableExamplesImpl * fix expected examples * add test to close https://github.com/nim-lang/Nim/issues/14473 * correctly handle regular comments before 1st token inside runnableExamples * add test to answer https://github.com/nim-lang/Nim/pull/14439#discussion_r431829199 * update tests
This commit is contained in:
parent
17d08ff71c
commit
e013ebc91a
12 changed files with 927 additions and 76 deletions
|
|
@ -436,18 +436,25 @@ proc ignoreMsgBecauseOfIdeTools(conf: ConfigRef; msg: TMsgKind): bool =
|
|||
proc addSourceLine(conf: ConfigRef; fileIdx: FileIndex, line: string) =
|
||||
conf.m.fileInfos[fileIdx.int32].lines.add line
|
||||
|
||||
proc sourceLine*(conf: ConfigRef; i: TLineInfo): string =
|
||||
if i.fileIndex.int32 < 0: return ""
|
||||
|
||||
if conf.m.fileInfos[i.fileIndex.int32].lines.len == 0:
|
||||
proc numLines*(conf: ConfigRef, fileIdx: FileIndex): int =
|
||||
## xxx there's an off by 1 error that should be fixed; if a file ends with "foo" or "foo\n"
|
||||
## it will return same number of lines (ie, a trailing empty line is discounted)
|
||||
result = conf.m.fileInfos[fileIdx.int32].lines.len
|
||||
if result == 0:
|
||||
try:
|
||||
for line in lines(toFullPathConsiderDirty(conf, i)):
|
||||
addSourceLine conf, i.fileIndex, line.string
|
||||
for line in lines(toFullPathConsiderDirty(conf, fileIdx).string):
|
||||
addSourceLine conf, fileIdx, line.string
|
||||
except IOError:
|
||||
discard
|
||||
assert i.fileIndex.int32 < conf.m.fileInfos.len
|
||||
result = conf.m.fileInfos[fileIdx.int32].lines.len
|
||||
|
||||
proc sourceLine*(conf: ConfigRef; i: TLineInfo): string =
|
||||
## 1-based index (matches editor line numbers); 1st line is for i.line = 1
|
||||
## last valid line is `numLines` inclusive
|
||||
if i.fileIndex.int32 < 0: return ""
|
||||
let num = numLines(conf, i.fileIndex)
|
||||
# can happen if the error points to EOF:
|
||||
if i.line.int > conf.m.fileInfos[i.fileIndex.int32].lines.len: return ""
|
||||
if i.line.int > num: return ""
|
||||
|
||||
result = conf.m.fileInfos[i.fileIndex.int32].lines[i.line.int-1]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue