Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tool: LSP support #879

Draft
wants to merge 92 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
e96d3f8
tool: LSP support
bung87 Sep 9, 2023
b10946c
use MarkupContent for hover
bung87 Sep 11, 2023
acb0222
fix indent problem
bung87 Sep 11, 2023
3fca2bc
handle admonition labels in Suggest.doc
bung87 Sep 11, 2023
3bc0ad1
refactor
bung87 Sep 11, 2023
e1e621f
use DocumentSymbol for outline
bung87 Sep 11, 2023
d8eb251
add license and remove nimble file
bung87 Sep 11, 2023
2cfafea
Suggest add flags field, only care deprecated pragma for now
bung87 Sep 12, 2023
700b15d
special cases for quoted procs
bung87 Sep 12, 2023
e697a89
outline no need filename param
bung87 Sep 12, 2023
23861dc
fix conflicts
bung87 Sep 13, 2023
8b9db0c
outline fill symbol detail distinguish variant variables and functions
bung87 Sep 14, 2023
72f13e4
tool: LSP support
bung87 Sep 9, 2023
ae01468
fix conflicts
bung87 Sep 13, 2023
6c709f4
refactor
bung87 Sep 16, 2023
8c01cf5
handle cachedMsgs
bung87 Sep 17, 2023
d8ccb36
fix conflicts
bung87 Sep 17, 2023
e8d28ca
lsp message log
bung87 Sep 17, 2023
586f3bb
comment checkVersion call
bung87 Sep 17, 2023
5bc5481
refactor checkVersion
bung87 Sep 17, 2023
4e8294e
remove exit log
bung87 Sep 17, 2023
6873deb
fix VerionMisMatch placeholder
bung87 Sep 17, 2023
c4b3fd3
refactor
bung87 Sep 17, 2023
7d0b10f
refactor logs
bung87 Sep 17, 2023
d47ecd3
configs
bung87 Sep 17, 2023
4479987
refactor
bung87 Sep 17, 2023
b382c00
refactor
bung87 Sep 17, 2023
bf8a831
refactor
bung87 Sep 17, 2023
124a4c6
refactor
bung87 Sep 17, 2023
6224b75
refactor
bung87 Sep 18, 2023
2c57496
refactor
bung87 Sep 18, 2023
6fcdc2e
refactor structuredReportHook
bung87 Sep 18, 2023
a79b547
refactor
bung87 Sep 18, 2023
39d5603
refactor
bung87 Sep 18, 2023
4ee6f71
refactor
bung87 Sep 18, 2023
bc68cdf
refactor
bung87 Sep 18, 2023
507bf31
refactor
bung87 Sep 18, 2023
448be9e
refactor
bung87 Sep 18, 2023
731b67d
refactor
bung87 Sep 18, 2023
f9aaecf
handle cachedMsgs;refactor
bung87 Sep 19, 2023
021e3f0
refactor
bung87 Sep 19, 2023
3d49eec
signatureHelp doc rstToMarkdown
bung87 Sep 19, 2023
00ec8e1
add more todos
bung87 Sep 19, 2023
c3ebcb7
progress handle
bung87 Sep 20, 2023
df97726
merge
bung87 Sep 22, 2023
adbeade
merege
bung87 Sep 22, 2023
7dcbfa0
handle pnkVarTuple
bung87 Sep 22, 2023
6bd7495
fix
bung87 Sep 22, 2023
9fd2b39
remove unrelated changes
bung87 Sep 24, 2023
873489d
remove unrelated changes
bung87 Sep 24, 2023
f3dab17
remove unrelated changes
bung87 Sep 24, 2023
fbb77f1
flags
bung87 Sep 24, 2023
418e600
outline sort
bung87 Sep 24, 2023
9b6f4c6
fix indent
bung87 Sep 24, 2023
1e105e3
fix indent
bung87 Sep 24, 2023
09f9c42
ignore gensym when outline
bung87 Sep 25, 2023
711811d
suggest proc later
bung87 Sep 25, 2023
33e86bc
outline ignore gensym by name
bung87 Sep 25, 2023
74ec400
unique reports
bung87 Sep 25, 2023
fab7c48
guard on suggestSym
bung87 Sep 25, 2023
337f652
code action type
bung87 Sep 25, 2023
a83ea3f
enable code action
bung87 Sep 26, 2023
34d033d
outline only suggest current tracked file
bung87 Sep 26, 2023
d0adbf7
fix suggest empty container error
bung87 Sep 26, 2023
d2eee4c
safe
bung87 Sep 26, 2023
04699e4
prepare code action
bung87 Sep 27, 2023
6de9480
avoid sfTemplateParam conflict error
bung87 Sep 27, 2023
23c4d32
add comments
bung87 Sep 27, 2023
fe3392e
unique reports
bung87 Sep 27, 2023
99a02cb
remove unused imports
bung87 Sep 27, 2023
f5b839a
report respect config.notes
bung87 Sep 27, 2023
4414034
Merge branch 'devel' into nimlsp5
bung87 Oct 1, 2023
bb34a45
Merge branch 'devel' into nimlsp5
bung87 Oct 5, 2023
5d58557
Merge remote-tracking branch 'upstream/devel' into nimlsp5
bung87 Oct 10, 2023
7dfb591
follow upstream changes
bung87 Oct 10, 2023
bf9b75f
follow upstream changes
bung87 Oct 10, 2023
6235d8f
report no symbol at position
bung87 Oct 11, 2023
9b1ecbd
fix when parentModule not found
bung87 Oct 11, 2023
697e445
fix rstToMarkdown
bung87 Oct 12, 2023
f977269
map label
bung87 Oct 12, 2023
107d6f8
generic params in outline
bung87 Oct 14, 2023
96e1dc9
clean readme
bung87 Oct 14, 2023
3244035
remove nimble file
bung87 Oct 14, 2023
c533c21
meta type guard
bung87 Oct 14, 2023
e7c9e86
Merge remote-tracking branch 'upstream/devel' into nimlsp5
bung87 Oct 18, 2023
b90eb55
unrelated changes
bung87 Oct 18, 2023
8057ad3
sync upstream
bung87 Oct 18, 2023
71ab5bb
Merge remote-tracking branch 'upstream/devel' into nimlsp5
bung87 Oct 19, 2023
1c42d2c
Merge remote-tracking branch 'upstream/devel' into nimlsp5
bung87 Oct 19, 2023
bee9534
Merge remote-tracking branch 'upstream/devel' into nimlsp5
bung87 Oct 22, 2023
6c8b8d2
Merge remote-tracking branch 'upstream/devel' into nimlsp5
bung87 Oct 28, 2023
2fd2c2d
sleep 16ms when using synchronous io
bung87 Jan 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/ast/reports.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
## `compilerDebugCompilerReportStatistics`: output stats of counts for various
## report kinds

import std/[options]
import std/[options, hashes]

import
compiler/ast/[
Expand Down Expand Up @@ -312,3 +312,8 @@ func actualType*(r: SemReport): PType = r.typeMismatch[0].actualType
func formalType*(r: SemReport): PType = r.typeMismatch[0].formalType
func formalTypeKind*(r: SemReport): set[TTypeKind] = r.typeMismatch[0].formalTypeKind
func symstr*(r: SemReport | VMReport): string = r.sym.name.s
func hash*(x: Report): Hash =
var h: Hash = 0
h = h !& hash(x.location().get(unknownLineInfo))
h = h !& x.kind.int
result = !$h
2 changes: 2 additions & 0 deletions compiler/sem/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3784,6 +3784,8 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
skProc
result[namePos] = semRoutineName(c, n[namePos], kind, allowAnon = true)
result = semProcAux(c, result, lambdaPragmas, flags)
if result.kind != nkError:
suggestSym(c.graph, result[namePos].info, result[namePos].sym, c.graph.usageSym)
of nkDerefExpr: result = semDeref(c, n)
of nkAddr:
result = n
Expand Down
9 changes: 7 additions & 2 deletions compiler/sem/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ proc semIdentDef(c: PContext, n: PNode, kind: TSymKind): PSym =
result.options = c.config.options

let info = getIdentLineInfo(n)
suggestSym(c.graph, info, result, c.graph.usageSym)
if kind != skType:
suggestSym(c.graph, info, result, c.graph.usageSym)

proc checkNilableOrError(c: PContext; def: PNode): PNode =
## checks if a symbol node is nilable, on success returns def, else nkError
Expand Down Expand Up @@ -2114,6 +2115,9 @@ proc typeSectionFinalPass(c: PContext, n: PNode) =
# fix bug #5170, bug #17162, bug #15526: ensure locally scoped types get a unique name:
if s.typ.kind in {tyEnum, tyRef, tyObject} and not isTopLevel(c):
incl(s.flags, sfGenSym)
when defined(nimsuggest):
if c.config.cmd == cmdIdeTools:
suggestSym(c.graph, s.info, s, c.graph.usageSym)

proc semTypeSection(c: PContext, n: PNode): PNode =
## Processes a type section. This must be done in separate passes, in order
Expand Down Expand Up @@ -2523,7 +2527,6 @@ proc semRoutineName(c: PContext, n: PNode, kind: TSymKind; allowAnon = true): PN
if c.isTopLevel:
incl(s.flags, sfGlobal)

suggestSym(c.graph, getIdentLineInfo(n), s, c.graph.usageSym)
styleCheckDef(c.config, s)
else:
# XXX: this should be the resonsibility of the macro sanitizer instead
Expand Down Expand Up @@ -3119,6 +3122,8 @@ proc semRoutineDef(c: PContext, n: PNode): PNode =
of skTemplate: semTemplateDef(c, result)
of skMacro: semMacroDef(c, result)
else: unreachable(kind)
if result.kind != nkError:
suggestSym(c.graph, result[namePos].info, result[namePos].sym, c.graph.usageSym)

proc evalInclude(c: PContext, n: PNode): PNode =
proc incMod(c: PContext, n, it, includeStmtResult: PNode) {.nimcall.} =
Expand Down
18 changes: 13 additions & 5 deletions compiler/tools/suggest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ proc symToSuggest(g: ModuleGraph; s: PSym, isLocal: bool, section: IdeCmd, info:
result.name = s.name.s
if isGenericRoutineStrict(s):
result.name.add renderTree(s.ast[genericParamsPos])
elif s.kind == skType and s.typ.isMetaType:
let len = s.typ.sons.len - 1
var genericParams = if len > 0: "[" else: ""
for i in 0 ..< len:
genericParams.add typeToString(s.typ.sons[i])
if i < len - 1: genericParams.add(", ")
if len > 0: genericParams.add "]"
result.name.add genericParams
when defined(nimsuggest):
if section in {ideSug, ideCon}:
result.globalUsages = s.allUsages.len
Expand Down Expand Up @@ -260,10 +268,10 @@ proc suggestField(c: PContext, s: PSym; f: PNode; info: TLineInfo; outputs: var
outputs.add(symToSuggest(c.graph, s, isLocal=true, ideSug, info,
s.getQuality, pm, c.inTypeContext > 0, 0))

template wholeSymTab(cond, section: untyped) {.dirty.} =
template wholeSymTab(cond, section: untyped) =
for (item, scopeN, isLocal) in allSyms(c):
let it = item
var pm: PrefixMatch
let it {.inject.} = item
var pm {.inject.}: PrefixMatch
if cond:
outputs.add(symToSuggest(c.graph, it, isLocal = isLocal, section, info, getQuality(it),
pm, c.inTypeContext > 0, scopeN))
Expand All @@ -285,9 +293,9 @@ proc suggestObject(c: PContext, n, f: PNode; info: TLineInfo, outputs: var Sugge
else: discard

proc nameFits(c: PContext, s: PSym, n: PNode): bool =
var op = if n.kind in nkCallKinds: n[0] else: n
var op = if n.kind in nkCallKinds and n.len > 0: n[0] else: n
if op.kind in {nkOpenSymChoice, nkClosedSymChoice}: op = op[0]
if op.kind == nkDotExpr: op = op[1]
if op.kind == nkDotExpr and op.len > 1: op = op[1]
var opr: PIdent
case op.kind
of nkSym: opr = op.sym.name
Expand Down
21 changes: 21 additions & 0 deletions nimlsp/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 PMunch

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
37 changes: 37 additions & 0 deletions nimlsp/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
==========
Nimskull Language Server Protocol
==========

This is a `Language Server Protocol
<https://microsoft.github.io/language-server-protocol/>`_ implementation in
Nimskull, for Nimskull.
It is based on nimsuggest, which means that every editor that
supports LSP will now have the same quality of suggestions that has previously
only been available in supported editors.

Supported Protocol features
=======

====== ================================
Status LSP Command
====== ================================
☑ DONE textDocument/didChange
☑ DONE textDocument/didClose
☑ DONE textDocument/didOpen
☑ DONE textDocument/didSave
☐ TODO textDocument/codeAction
☑ DONE textDocument/completion
☑ DONE textDocument/definition
☐ TODO textDocument/documentHighlight
☑ DONE textDocument/documentSymbol
☐ TODO textDocument/executeCommand
☐ TODO textDocument/format
☑ DONE textDocument/hover
☑ DONE textDocument/rename
☑ DONE textDocument/references
☑ DONE textDocument/signatureHelp
☑ DONE textDocument/publishDiagnostics
☐ TODO workspace/symbol
☐ TODO `$/progress<https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workDoneProgress>`
☐ TODO `textDocument/codeAction<https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeAction>`
====== ================================
4 changes: 4 additions & 0 deletions nimlsp/config.nims
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import std/os

const explicitSourcePath {.strdefine.} = getCurrentCompilerExe().parentDir.parentDir
switch "path", explicitSourcePath
Loading