Skip to content

Commit a842e7a

Browse files
authored
Applies nph format to src files (#106)
1 parent 58bf0bc commit a842e7a

35 files changed

+2325
-1902
lines changed

nimvscode.nimble

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# Package
22

3-
version = "1.2.0"
4-
author = "saem"
3+
version = "1.2.0"
4+
author = "saem"
55
description = "Nim language support for Visual Studio Code written in Nim"
6-
license = "MIT"
7-
backend = "js"
8-
srcDir = "src"
9-
binDir = "out"
10-
bin = @["nimvscode"]
6+
license = "MIT"
7+
backend = "js"
8+
srcDir = "src"
9+
binDir = "out"
10+
bin = @["nimvscode"]
1111

1212
# Deps
1313

1414
requires "nim >= 2.0.0 & <= 2.1"
1515

1616
import std/os
1717

18-
proc initialNpmInstall =
18+
proc initialNpmInstall() =
1919
if not dirExists "node_modules":
2020
exec "npm install"
2121

@@ -27,7 +27,7 @@ task release, "This compiles a release version":
2727
exec "nim js -d:release -d:danger --outdir:out --checks:off --sourceMap src/nimvscode.nim"
2828

2929
task vsix, "Build VSIX package":
30-
initialNpmInstall()
30+
initialNpmInstall()
3131
var cmd = "npm exec -c 'vsce package --out out/nimvscode-" & version & ".vsix'"
3232
when defined(windows):
3333
cmd = "powershell.exe " & cmd

src/nimDeclaration.nim

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,34 @@ import platform/vscodeApi
44
import nimSuggestExec
55

66
proc provideDefinition*(
7-
doc: VscodeTextDocument,
8-
position: VscodePosition,
9-
token: VscodeCancellationToken
7+
doc: VscodeTextDocument, position: VscodePosition, token: VscodeCancellationToken
108
): Promise[Array[VscodeLocation]] =
119
## TODO - the return type is a sub-set of what's in the TypeScript API
1210
## Since we're providing the result this isn't a practical problem
13-
return newPromise(proc (
14-
resolve: proc(val: Array[VscodeLocation]),
15-
reject: proc(reason: JsObject)
16-
) =
17-
let pos: cint = position.line + 1
18-
execNimSuggest(
19-
NimSuggestType.def,
20-
doc.fileName,
21-
pos,
22-
position.character,
23-
true,
24-
doc.getText()
25-
).then(
26-
proc(result: seq[NimSuggestResult]) =
27-
if(not result.isNull() and not result.isUndefined() and result.len > 0):
28-
let locations = newArray[VscodeLocation]()
29-
for def in result:
30-
if not(def.isUndefined() or def.isNull()):
31-
locations.push def.location
11+
return newPromise(
12+
proc(resolve: proc(val: Array[VscodeLocation]), reject: proc(reason: JsObject)) =
13+
let pos: cint = position.line + 1
3214

33-
if locations.len > 0:
34-
resolve(locations)
15+
execNimSuggest(
16+
NimSuggestType.def, doc.fileName, pos, position.character, true, doc.getText()
17+
)
18+
.then(
19+
proc(result: seq[NimSuggestResult]) =
20+
if (not result.isNull() and not result.isUndefined() and result.len > 0):
21+
let locations = newArray[VscodeLocation]()
22+
for def in result:
23+
if not (def.isUndefined() or def.isNull()):
24+
locations.push def.location
3525

36-
resolve(jsNull.to(Array[VscodeLocation]))
37-
).catch(proc(reason: JsObject) = reject(reason))
26+
if locations.len > 0:
27+
resolve(locations)
28+
29+
resolve(jsNull.to(Array[VscodeLocation]))
30+
)
31+
.catch(
32+
proc(reason: JsObject) =
33+
reject(reason)
34+
)
3835
)
3936

4037
var nimDefinitionProvider* {.exportc.} = block:

src/nimFormatting.nim

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,28 @@ from tools/nimBinTools import getNimPrettyExecPath
1313
var extensionContext*: VscodeExtensionContext
1414

1515
proc provideDocumentFormattingEdits*(
16-
doc: VscodeTextDocument,
17-
options: VscodeFormattingOptions,
18-
token: VscodeCancellationToken
16+
doc: VscodeTextDocument,
17+
options: VscodeFormattingOptions,
18+
token: VscodeCancellationToken,
1919
): Future[seq[VscodeTextEdit]] {.async.} =
2020
var ret: seq[VscodeTextEdit] = @[]
2121
if getNimPrettyExecPath() == "":
22-
vscode.window.showInformationMessage("No 'nimpretty' binary could be found in PATH environment variable")
22+
vscode.window.showInformationMessage(
23+
"No 'nimpretty' binary could be found in PATH environment variable"
24+
)
2325
return ret
2426

2527
var file = getDirtyFile(doc)
2628
var config = vscode.workspace.getConfiguration("nim")
2729
var res = cp.spawnSync(
28-
getNimPrettyExecPath(),
29-
@[
30-
cstring "--backup:OFF",
31-
"--indent:" & cstring($(config.getInt("nimprettyIndent"))),
32-
"--maxLineLen:" & cstring($(config.getInt("nimprettyMaxLineLen"))),
33-
file
30+
getNimPrettyExecPath(),
31+
@[
32+
cstring "--backup:OFF",
33+
"--indent:" & cstring($(config.getInt("nimprettyIndent"))),
34+
"--maxLineLen:" & cstring($(config.getInt("nimprettyMaxLineLen"))),
35+
file,
3436
],
35-
SpawnSyncOptions{cwd: extensionContext.extensionPath}
37+
SpawnSyncOptions{cwd: extensionContext.extensionPath},
3638
)
3739

3840
if res.status != 0:
@@ -45,14 +47,13 @@ proc provideDocumentFormattingEdits*(
4547
return ret
4648

4749
var content = fs.readFileSync(file, "utf-8")
48-
var `range` = doc.validateRange(vscode.newRange(
49-
vscode.newPosition(0, 0),
50-
vscode.newPosition(1000000, 1000000))
50+
var `range` = doc.validateRange(
51+
vscode.newRange(vscode.newPosition(0, 0), vscode.newPosition(1000000, 1000000))
5152
)
5253
ret.add(vscode.textEditReplace(`range`, content))
5354
return ret
5455

5556
var nimFormattingProvider* {.exportc.} = block:
56-
var o = newJsObject()
57-
o.provideDocumentFormattingEdits = provideDocumentFormattingEdits
58-
o.to(VscodeDocumentFormattingEditProvider)
57+
var o = newJsObject()
58+
o.provideDocumentFormattingEdits = provideDocumentFormattingEdits
59+
o.to(VscodeDocumentFormattingEditProvider)

src/nimHover.nim

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,46 @@ import nimSuggestExec
66
import nimMode
77

88
proc provideHover*(
9-
doc: VscodeTextDocument,
10-
position: VscodePosition,
11-
token: VscodeCancellationToken
9+
doc: VscodeTextDocument, position: VscodePosition, token: VscodeCancellationToken
1210
): Promise[VscodeHover] =
13-
return newPromise(proc (
14-
resolve: proc(val: VscodeHover),
15-
reject: proc(reason: JsObject)
16-
) =
17-
var pos: cint = position.line + 1
18-
execNimSuggest(
19-
NimSuggestType.def,
20-
doc.fileName,
21-
pos,
22-
position.character,
23-
true,
24-
doc.getText()
25-
).then(proc(items: seq[NimSuggestResult]) =
26-
if(not items.isNull() and not items.isUndefined() and items.len > 0):
27-
var definition = items[items.len - 1]
28-
var label = definition.fullName
11+
return newPromise(
12+
proc(resolve: proc(val: VscodeHover), reject: proc(reason: JsObject)) =
13+
var pos: cint = position.line + 1
2914

30-
if definition.`type` != "":
31-
label &= ": " & definition.`type`
32-
var hoverLabel: VscodeMarkedString = VscodeHoverLabel{
33-
language: mode.language, value: label}
15+
execNimSuggest(
16+
NimSuggestType.def, doc.fileName, pos, position.character, true, doc.getText()
17+
)
18+
.then(
19+
proc(items: seq[NimSuggestResult]) =
20+
if (not items.isNull() and not items.isUndefined() and items.len > 0):
21+
var definition = items[items.len - 1]
22+
var label = definition.fullName
3423

35-
if definition.documentation != "":
36-
resolve(vscode.newVscodeHover(newArrayWith[VscodeMarkedString](hoverLabel, definition.documentation)))
37-
else:
38-
resolve(vscode.newVscodeHover(newArrayWith[VscodeMarkedString](hoverLabel)))
39-
else:
40-
resolve(jsUndefined.to(VscodeHover))
41-
).catch(proc(reason: JsObject) = reject(reason))
24+
if definition.`type` != "":
25+
label &= ": " & definition.`type`
26+
var hoverLabel: VscodeMarkedString =
27+
VscodeHoverLabel{language: mode.language, value: label}
28+
29+
if definition.documentation != "":
30+
resolve(
31+
vscode.newVscodeHover(
32+
newArrayWith[VscodeMarkedString](hoverLabel, definition.documentation)
33+
)
34+
)
35+
else:
36+
resolve(
37+
vscode.newVscodeHover(newArrayWith[VscodeMarkedString](hoverLabel))
38+
)
39+
else:
40+
resolve(jsUndefined.to(VscodeHover))
41+
)
42+
.catch(
43+
proc(reason: JsObject) =
44+
reject(reason)
45+
)
4246
)
4347

4448
var nimHoverProvider* {.exportc.} = block:
45-
var o = newJsObject()
46-
o.provideHover = provideHover
47-
o.to(VscodeHoverProvider)
49+
var o = newJsObject()
50+
o.provideHover = provideHover
51+
o.to(VscodeHoverProvider)

0 commit comments

Comments
 (0)