Advertisement
Guest User

Untitled

a guest
Nov 26th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.87 KB | None | 0 0
  1. Version: 0.2.5
  2.  
  3. explicitSourcePath: /home/arjun/.choosenim/toolchains/nim-1.4.0
  4.  
  5. Trying to read frame
  6.  
  7. Got frame:
  8. {"jsonrpc":"2.0","method":"initialize","params":{"processId":null,"rootPath":"/home/arjun/Documents/sources/nimlsp","clientInfo":{"name":"emacs","version":"GNU Emacs 28.0.50 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.23, cairo version 1.16.0)\n of 2020-11-22"},"rootUri":"file:///home/arjun/Documents/sources/nimlsp","capabilities":{"workspace":{"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"]},"applyEdit":true,"symbol":{"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"executeCommand":{"dynamicRegistration":false},"didChangeWatchedFiles":{"dynamicRegistration":true},"workspaceFolders":true,"configuration":true},"textDocument":{"declaration":{"linkSupport":true},"definition":{"linkSupport":true},"implementation":{"linkSupport":true},"typeDefinition":{"linkSupport":true},"synchronization":{"willSave":true,"didSave":true,"willSaveWaitUntil":true},"documentSymbol":{"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"codeAction":{"dynamicRegistration":true,"isPreferredSupport":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"completion":{"completionItem":{"snippetSupport":true,"documentationFormat":["markdown"],"resolveAdditionalTextEditsSupport":true},"contextSupport":true},"signatureHelp":{"signatureInformation":{"parameterInformation":{"labelOffsetSupport":true}}},"documentLink":{"dynamicRegistration":true,"tooltipSupport":true},"hover":{"contentFormat":["markdown","plaintext"]},"foldingRange":{"dynamicRegistration":true},"callHierarchy":{"dynamicRegistration":false},"publishDiagnostics":{"relatedInformation":true,"tagSupport":{"valueSet":[1,2]},"versionSupport":true}},"window":{"workDoneProgress":true}},"initializationOptions":null,"workDoneToken":"1"},"id":45}
  9.  
  10.  
  11. Got valid Request message of type initialize
  12.  
  13. Got initialize request, answering
  14.  
  15. Trying to read frame
  16.  
  17. Got frame:
  18. {"jsonrpc":"2.0","method":"initialized","params":{}}
  19.  
  20.  
  21. Unable to parse data as RequestMessage
  22.  
  23. Got valid Notification message of type initialized
  24.  
  25. Properly initialized
  26.  
  27. Trying to read frame
  28.  
  29. Got frame:
  30. {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///home/arjun/Documents/sources/nimlsp/src/nimlsp.nim","languageId":"nim","version":29,"text":"import nimlsppkg / [baseprotocol, utfmapping, suggestlib]\ninclude nimlsppkg / messages\nimport algorithm\nimport streams\nimport tables\nimport strutils\nimport os\nimport hashes\nimport uri\nimport osproc\nimport stream\nisEmp\nconst\n storage = getTempDir() / \"nimlsp\"\n version = block:\n var version = \"0.0.0\"\n let nimbleFile = staticRead(currentSourcePath().parentDir().parentDir() / \"nimlsp.nimble\")\n for line in nimbleFile.splitLines:\n let keyval = line.split(\"=\")\n if keyval.len == 2:\n if keyval[0].strip == \"version\":\n version = keyval[1].strip(chars = Whitespace + {'\"'})\n break\n version\n # This is used to explicitly set the default source path\n explicitSourcePath {.strdefine.} = getCurrentCompilerExe().parentDir.parentDir\n\ntype\n UriParseError* = object of Defect\n uri: string\n\nvar nimpath = explicitSourcePath\n\ndiscard existsOrCreateDir(storage)\n\nwhen defined(debugLogging):\n var logFile = open(storage / \"nimlsp.log\", fmWrite)\n\ntemplate debugEcho(args: varargs[string, `$`]) =\n when defined(debugLogging):\n stderr.write(join args)\n stderr.write(\"\\n\")\n logFile.write(join args)\n logFile.write(\"\\n\\n\")\n logFile.flushFile()\n\ndebugEcho(\"Version: \", version)\ndebugEcho(\"explicitSourcePath: \", explicitSourcePath)\nfor i in 1..paramCount():\n debugEcho(\"Argument \" & $i & \": \" & paramStr(i))\n\nvar\n ins = newFileStream(stdin)\n outs = newFileStream(stdout)\n gotShutdown = false\n initialized = false\n projectFiles = initTable[string, tuple[nimsuggest: NimSuggest, openFiles: int]]()\n openFiles = initTable[string, tuple[projectFile: string, fingerTable: seq[seq[tuple[u16pos, offset: int]]]]]()\n\ntemplate whenValid(data, kind, body) =\n if data.isValid(kind):\n var data = kind(data)\n body\n else:\n debugEcho(\"Unable to parse data as \" & $kind)\n\ntemplate whenValid(data, kind, body, elseblock) =\n if data.isValid(kind, allowExtra = true):\n var data = kind(data)\n body\n else:\n elseblock\n\ntemplate textDocumentRequest(message, kind, name, body) {.dirty.} =\n if message[\"params\"].isSome:\n let name = message[\"params\"].unsafeGet\n whenValid(name, kind):\n let\n fileuri = name[\"textDocument\"][\"uri\"].getStr\n filestash = storage / (hash(fileuri).toHex & \".nim\" )\n debugEcho \"Got request for URI: \", fileuri, \" copied to \" & filestash\n when kind isnot DocumentSymbolParams:\n let\n rawLine = name[\"position\"][\"line\"].getInt\n rawChar = name[\"position\"][\"character\"].getInt\n body\n\ntemplate textDocumentNotification(message, kind, name, body) {.dirty.} =\n if message[\"params\"].isSome:\n let name = message[\"params\"].unsafeGet\n whenValid(name, kind):\n if not name[\"textDocument\"].hasKey(\"languageId\") or name[\"textDocument\"][\"languageId\"].getStr == \"nim\":\n let\n fileuri = name[\"textDocument\"][\"uri\"].getStr\n filestash = storage / (hash(fileuri).toHex & \".nim\" )\n body\n\nproc pathToUri(path: string): string =\n # This is a modified copy of encodeUrl in the uri module. This doesn't encode\n # the / character, meaning a full file path can be passed in without breaking\n # it.\n result = newStringOfCap(path.len + path.len shr 2) # assume 12% non-alnum-chars\n for c in path:\n case c\n # https://tools.ietf.org/html/rfc3986#section-2.3\n of 'a'..'z', 'A'..'Z', '0'..'9', '-', '.', '_', '~', '/': add(result, c)\n else:\n add(result, '%')\n add(result, toHex(ord(c), 2))\n\nproc uriToPath(uri: string): string =\n ## Convert an RFC 8089 file URI to a native, platform-specific, absolute path.\n #let startIdx = when defined(windows): 8 else: 7\n #normalizedPath(uri[startIdx..^1])\n let parsed = uri.parseUri\n if parsed.scheme != \"file\":\n var e = newException(UriParseError, \"Invalid scheme: \" & parsed.scheme & \", only \\\"file\\\" is supported\")\n e.uri = uri\n raise e\n if parsed.hostname != \"\":\n var e = newException(UriParseError, \"Invalid hostname: \" & parsed.hostname & \", only empty hostname is supported\")\n e.uri = uri\n raise e\n return normalizedPath(\n when defined(windows):\n parsed.path[1..^1]\n else:\n parsed.path).decodeUrl\n\nproc parseId(node: JsonNode): int =\n if node.kind == JString:\n parseInt(node.getStr)\n elif node.kind == JInt:\n node.getInt\n else:\n raise newException(MalformedFrame, \"Invalid id node: \" & repr(node))\n\nproc respond(request: RequestMessage, data: JsonNode) =\n outs.sendJson create(ResponseMessage, \"2.0\", parseId(request[\"id\"]), some(data), none(ResponseError)).JsonNode\n\nproc error(request: RequestMessage, errorCode: int, message: string, data: JsonNode) =\n outs.sendJson create(ResponseMessage, \"2.0\", parseId(request[\"id\"]), none(JsonNode), some(create(ResponseError, errorCode, message, data))).JsonNode\n\nproc notify(notification: string, data: JsonNode) =\n outs.sendJson create(NotificationMessage, \"2.0\", notification, some(data)).JsonNode\n\ntype Certainty = enum\n None,\n Folder,\n Cfg,\n Nimble\n\nproc getProjectFile(fileUri: string): string =\n let file = fileUri.decodeUrl\n result = file\n let (dir, _, _) = result.splitFile()\n var\n path = dir\n certainty = None\n while path.len > 0 and path != \"/\":\n let\n (dir, fname, ext) = path.splitFile()\n current = fname & ext\n if fileExists(path / current.addFileExt(\".nim\")) and certainty <= Folder:\n result = path / current.addFileExt(\".nim\")\n certainty = Folder\n if fileExists(path / current.addFileExt(\".nim\")) and\n (fileExists(path / current.addFileExt(\".nim.cfg\")) or\n fileExists(path / current.addFileExt(\".nims\"))) and certainty <= Cfg:\n result = path / current.addFileExt(\".nim\")\n certainty = Cfg\n if certainty <= Nimble:\n for nimble in walkFiles(path / \"*.nimble\"):\n let info = execProcess(\"nimble dump \" & nimble)\n var sourceDir, name: string\n for line in info.splitLines:\n if line.startsWith(\"srcDir\"):\n sourceDir = path / line[(1 + line.find '\"')..^2]\n if line.startsWith(\"name\"):\n name = line[(1 + line.find '\"')..^2]\n let projectFile = sourceDir / (name & \".nim\")\n if sourceDir.len != 0 and name.len != 0 and\n file.isRelativeTo(sourceDir) and fileExists(projectFile):\n result = projectFile\n certainty = Nimble\n path = dir\n\ntemplate getNimsuggest(fileuri: string): Nimsuggest =\n projectFiles[openFiles[fileuri].projectFile].nimsuggest\n\nif paramCount() == 1:\n case paramStr(1):\n of \"--help\":\n echo \"Usage: nimlsp [OPTION | PATH]\\n\"\n echo \"--help, shows this message\"\n echo \"--version, shows only the version\"\n echo \"PATH, path to the Nim source directory, defaults to \\\"\", nimpath, \"\\\"\"\n quit 0\n of \"--version\":\n echo \"nimlsp v\", version\n quit 0\n else: nimpath = expandFilename(paramStr(1))\nif not fileExists(nimpath / \"config/nim.cfg\"):\n stderr.write \"Unable to find \\\"config/nim.cfg\\\" in \\\"\" & nimpath & \"\\\". \" &\n \"Supply the Nim project folder by adding it as an argument.\\n\"\n quit 1\n\nwhile true:\n try:\n debugEcho \"Trying to read frame\"\n let frame = ins.readFrame\n debugEcho \"Got frame:\\n\" & frame\n let message = frame.parseJson\n whenValid(message, RequestMessage):\n debugEcho \"Got valid Request message of type \" & message[\"method\"].getStr\n if not initialized and message[\"method\"].getStr != \"initialize\":\n message.error(-32002, \"Unable to accept requests before being initialized\", newJNull())\n continue\n case message[\"method\"].getStr:\n of \"shutdown\":\n debugEcho \"Got shutdown request, answering\"\n message.respond(newJNull())\n gotShutdown = true\n of \"initialize\":\n debugEcho \"Got initialize request, answering\"\n initialized = true\n message.respond(create(InitializeResult, create(ServerCapabilities,\n textDocumentSync = some(create(TextDocumentSyncOptions,\n openClose = some(true),\n change = some(TextDocumentSyncKind.Full.int),\n willSave = some(false),\n willSaveWaitUntil = some(false),\n save = some(create(SaveOptions, some(true)))\n )), # ?: TextDocumentSyncOptions or int or float\n hoverProvider = some(true), # ?: bool\n completionProvider = some(create(CompletionOptions,\n resolveProvider = some(true),\n triggerCharacters = some(@[\".\", \" \"])\n )), # ?: CompletionOptions\n signatureHelpProvider = none(SignatureHelpOptions),\n #signatureHelpProvider = some(create(SignatureHelpOptions,\n # triggerCharacters = some(@[\"(\", \",\"])\n #)), # ?: SignatureHelpOptions\n definitionProvider = some(true), #?: bool\n typeDefinitionProvider = none(bool), #?: bool or TextDocumentAndStaticRegistrationOptions\n implementationProvider = none(bool), #?: bool or TextDocumentAndStaticRegistrationOptions\n referencesProvider = some(true), #?: bool\n documentHighlightProvider = none(bool), #?: bool\n documentSymbolProvider = some(true), #?: bool\n workspaceSymbolProvider = none(bool), #?: bool\n codeActionProvider = none(bool), #?: bool\n codeLensProvider = none(CodeLensOptions), #?: CodeLensOptions\n documentFormattingProvider = none(bool), #?: bool\n documentRangeFormattingProvider = none(bool), #?: bool\n documentOnTypeFormattingProvider = none(DocumentOnTypeFormattingOptions), #?: DocumentOnTypeFormattingOptions\n renameProvider = some(true), #?: bool\n documentLinkProvider = none(DocumentLinkOptions), #?: DocumentLinkOptions\n colorProvider = none(bool), #?: bool or ColorProviderOptions or TextDocumentAndStaticRegistrationOptions\n executeCommandProvider = none(ExecuteCommandOptions), #?: ExecuteCommandOptions\n workspace = none(WorkspaceCapability), #?: WorkspaceCapability\n experimental = none(JsonNode) #?: any\n )).JsonNode)\n of \"textDocument/completion\":\n message.textDocumentRequest(CompletionParams, compRequest):\n debugEcho \"Running equivalent of: sug \", uriToPath(fileuri), \";\", filestash, \":\",\n rawLine + 1, \":\",\n openFiles[fileuri].fingerTable[rawLine].utf16to8(rawChar)\n let suggestions = getNimsuggest(fileuri).sug(uriToPath(fileuri), dirtyfile = filestash,\n rawLine + 1,\n openFiles[fileuri].fingerTable[rawLine].utf16to8(rawChar)\n )\n debugEcho \"Found suggestions: \",\n suggestions[0..(if suggestions.len > 10: 10 else: suggestions.high)],\n (if suggestions.len > 10: \" and \" & $(suggestions.len-10) & \" more\" else: \"\")\n var completionItems = newJarray()\n for suggestion in suggestions:\n completionItems.add create(CompletionItem,\n label = suggestion.qualifiedPath[^1],\n kind = some(nimSymToLSPKind(suggestion).int),\n detail = some(nimSymDetails(suggestion)),\n documentation = some(suggestion.nimDocstring),\n deprecated = none(bool),\n preselect = none(bool),\n sortText = none(string),\n filterText = none(string),\n insertText = none(string),\n insertTextFormat = none(int),\n textEdit = none(TextEdit),\n additionalTextEdits = none(seq[TextEdit]),\n commitCharacters = none(seq[string]),\n command = none(Command),\n data = none(JsonNode)\n ).JsonNode\n message.respond completionItems\n of \"textDocument/hover\":\n message.textDocumentRequest(TextDocumentPositionParams, hoverRequest):\n debugEcho \"Running equivalent of: def \", uriToPath(fileuri), \";\", filestash, \":\",\n rawLine + 1, \":\",\n openFiles[fileuri].fingerTable[rawLine].utf16to8(rawChar)\n let suggestions = getNimsuggest(fileuri).def(uriToPath(fileuri), dirtyfile = filestash,\n rawLine + 1,\n openFiles[fileuri].fingerTable[rawLine].utf16to8(rawChar)\n )\n debugEcho \"Found suggestions: \",\n suggestions[0..(if suggestions.len > 10: 10 else: suggestions.high)],\n (if suggestions.len > 10: \" and \" & $(suggestions.len-10) & \" more\" else: \"\")\n if suggestions.len == 0:\n message.respond newJNull()\n else:\n var label = suggestions[0].qualifiedPath.join(\".\")\n if suggestions[0].forth != \"\":\n label &= \": \" & suggestions[0].forth\n let\n rangeopt =\n some(create(Range,\n create(Position, rawLine, rawChar),\n create(Position, rawLine, rawChar + suggestions[0].qualifiedPath[^1].len)\n ))\n markedString = create(MarkedStringOption, \"nim\", label)\n if suggestions[0].doc != \"\":\n message.respond create(Hover,\n @[\n markedString,\n create(MarkedStringOption, \"\", suggestions[0].nimDocstring),\n ],\n rangeopt\n ).JsonNode\n else:\n message.respond create(Hover, markedString, rangeopt).JsonNode\n of \"textDocument/references\":\n message.textDocumentRequest(ReferenceParams, referenceRequest):\n debugEcho \"Running equivalent of: use \", uriToPath(fileuri), \";\", filestash, \":\",\n rawLine + 1, \":\",\n openFiles[fileuri].fingerTable[rawLine].utf16to8(rawChar)\n let suggestions = getNimsuggest(fileuri).use(uriToPath(fileuri), dirtyfile = filestash,\n rawLine + 1,\n openFiles[fileuri].fingerTable[rawLine].utf16to8(rawChar)\n )\n debugEcho \"Found suggestions: \",\n suggestions[0..(if suggestions.len > 10: 10 else: suggestions.high)],\n (if suggestions.len > 10: \" and \" & $(suggestions.len-10) & \" more\" else: \"\")\n var response = newJarray()\n for suggestion in suggestions:\n if suggestion.section == ideUse or referenceRequest[\"context\"][\"includeDeclaration\"].getBool:\n response.add create(Location,\n \"file://\" & pathToUri(suggestion.filepath),\n create(Range,\n create(Position, suggestion.line-1, suggestion.column),\n create(Position, suggestion.line-1, suggestion.column + suggestion.qualifiedPath[^1].len)\n )\n ).JsonNode\n if response.len == 0:\n message.respond newJNull()\n else:\n message.respond response\n of \"textDocument/rename\":\n message.textDocumentRequest(RenameParams, renameRequest):\n debugEcho \"Running equivalent of: use \", uriToPath(fileuri), \";\", filestash, \":\",\n rawLine + 1, \":\",\n openFiles[fileuri].fingerTable[rawLine].utf16to8(rawChar)\n let suggestions = getNimsuggest(fileuri).use(uriToPath(fileuri), dirtyfile = filestash,\n rawLine + 1,\n openFiles[fileuri].fingerTable[rawLine].utf16to8(rawChar)\n )\n debugEcho \"Found suggestions: \",\n suggestions[0..(if suggestions.len > 10: 10 else: suggestions.high)],\n (if suggestions.len > 10: \" and \" & $(suggestions.len-10) & \" more\" else: \"\")\n if suggestions.len == 0:\n message.respond newJNull()\n else:\n var textEdits = newJObject()\n for suggestion in suggestions:\n if not textEdits.hasKey(\"file://\" & pathToUri(suggestion.filepath)):\n textEdits[\"file://\" & pathToUri(suggestion.filepath)] = newJArray()\n textEdits[\"file://\" & pathToUri(suggestion.filepath)].add create(TextEdit,\n create(Range,\n create(Position, suggestion.line-1, suggestion.column),\n create(Position, suggestion.line-1, suggestion.column + suggestion.qualifiedPath[^1].len)\n ),\n renameRequest[\"newName\"].getStr\n ).JsonNode\n message.respond create(WorkspaceEdit,\n some(textEdits),\n none(seq[TextDocumentEdit])\n ).JsonNode\n of \"textDocument/definition\":\n message.textDocumentRequest(TextDocumentPositionParams, definitionRequest):\n debugEcho \"Running equivalent of: def \", uriToPath(fileuri), \";\", filestash, \":\",\n rawLine + 1, \":\",\n openFiles[fileuri].fingerTable[rawLine].utf16to8(rawChar)\n let declarations = getNimsuggest(fileuri).def(uriToPath(fileuri), dirtyfile = filestash,\n rawLine + 1,\n openFiles[fileuri].fingerTable[rawLine].utf16to8(rawChar)\n )\n debugEcho \"Found suggestions: \",\n declarations[0..(if declarations.len > 10: 10 else: declarations.high)],\n (if declarations.len > 10: \" and \" & $(declarations.len-10) & \" more\" else: \"\")\n if declarations.len == 0:\n message.respond newJNull()\n else:\n var response = newJarray()\n for declaration in declarations:\n response.add create(Location,\n \"file://\" & pathToUri(declaration.filepath),\n create(Range,\n create(Position, declaration.line-1, declaration.column),\n create(Position, declaration.line-1, declaration.column + declaration.qualifiedPath[^1].len)\n )\n ).JsonNode\n message.respond response\n of \"textDocument/documentSymbol\":\n message.textDocumentRequest(DocumentSymbolParams, symbolRequest):\n debugEcho \"Running equivalent of: outline \", uriToPath(fileuri), \";\", filestash\n let syms = getNimsuggest(fileuri).outline(uriToPath(fileuri), dirtyfile = filestash)\n debugEcho \"Found outlines: \",\n syms[0..(if syms.len > 10: 10 else: syms.high)],\n (if syms.len > 10: \" and \" & $(syms.len-10) & \" more\" else: \"\")\n if syms.len == 0:\n message.respond newJNull()\n else:\n var response = newJarray()\n for sym in syms.sortedByIt((it.line,it.column,it.quality)):\n if sym.qualifiedPath.len != 2:\n continue\n response.add create(\n SymbolInformation,\n sym.name[],\n nimSymToLSPKind(sym.symKind).int,\n some(false),\n create(Location,\n \"file://\" & pathToUri(sym.filepath),\n create(Range,\n create(Position, sym.line-1, sym.column),\n create(Position, sym.line-1, sym.column + sym.qualifiedPath[^1].len)\n )\n ),\n none(string)\n ).JsonNode\n message.respond response\n #of \"textDocument/signatureHelp\":\n # if message[\"params\"].isSome:\n # let signRequest = message[\"params\"].unsafeGet\n # whenValid(signRequest, TextDocumentPositionParams):\n # let\n # fileuri = signRequest[\"textDocument\"][\"uri\"].getStr\n # filestash = storage / (hash(fileuri).toHex & \".nim\" )\n # debugEcho \"Got signature request for URI: \", fileuri, \" copied to \" & filestash\n # let\n # rawLine = signRequest[\"position\"][\"line\"].getInt\n # rawChar = signRequest[\"position\"][\"character\"].getInt\n # suggestions = getNimsuggest(fileuri).con(uriToPath(fileuri), dirtyfile = filestash, rawLine + 1, rawChar)\n\n else:\n debugEcho \"Unknown request\"\n continue\n whenValid(message, NotificationMessage):\n debugEcho \"Got valid Notification message of type \" & message[\"method\"].getStr\n if not initialized and message[\"method\"].getStr != \"exit\":\n continue\n case message[\"method\"].getStr:\n of \"exit\":\n debugEcho \"Exiting\"\n if gotShutdown:\n quit 0\n else:\n quit 1\n of \"initialized\":\n debugEcho \"Properly initialized\"\n of \"textDocument/didOpen\":\n message.textDocumentNotification(DidOpenTextDocumentParams, textDoc):\n let\n file = open(filestash, fmWrite)\n projectFile = getProjectFile(uriToPath(fileuri))\n debugEcho \"New document opened for URI: \", fileuri, \" saving to \" & filestash\n openFiles[fileuri] = (\n #nimsuggest: initNimsuggest(uriToPath(fileuri)),\n projectFile: projectFile,\n fingerTable: @[]\n )\n if not projectFiles.hasKey(projectFile):\n debugEcho \"Initialising project with \", projectFile, \":\", nimpath\n projectFiles[projectFile] = (nimsuggest: initNimsuggest(projectFile, nimpath), openFiles: 1)\n else:\n projectFiles[projectFile].openFiles += 1\n for line in textDoc[\"textDocument\"][\"text\"].getStr.splitLines:\n openFiles[fileuri].fingerTable.add line.createUTFMapping()\n file.writeLine line\n file.close()\n of \"textDocument/didChange\":\n message.textDocumentNotification(DidChangeTextDocumentParams, textDoc):\n let file = open(filestash, fmWrite)\n debugEcho \"Got document change for URI: \", fileuri, \" saving to \" & filestash\n openFiles[fileuri].fingerTable = @[]\n for line in textDoc[\"contentChanges\"][0][\"text\"].getStr.splitLines:\n openFiles[fileuri].fingerTable.add line.createUTFMapping()\n file.writeLine line\n file.close()\n of \"textDocument/didClose\":\n message.textDocumentNotification(DidCloseTextDocumentParams, textDoc):\n let projectFile = getProjectFile(uriToPath(fileuri))\n debugEcho \"Got document close for URI: \", fileuri, \" copied to \" & filestash\n removeFile(filestash)\n projectFiles[projectFile].openFiles -= 1\n if projectFiles[projectFile].openFiles == 0:\n debugEcho \"Trying to stop nimsuggest\"\n debugEcho \"Stopped nimsuggest with code: \" & $getNimsuggest(fileuri).stopNimsuggest()\n openFiles.del(fileuri)\n of \"textDocument/didSave\":\n message.textDocumentNotification(DidSaveTextDocumentParams, textDoc):\n if textDoc[\"text\"].isSome:\n let file = open(filestash, fmWrite)\n debugEcho \"Got document save for URI: \", fileuri, \" saving to \", filestash\n openFiles[fileuri].fingerTable = @[]\n for line in textDoc[\"text\"].unsafeGet.getStr.splitLines:\n openFiles[fileuri].fingerTable.add line.createUTFMapping()\n file.writeLine line\n file.close()\n debugEcho \"fileuri: \", fileuri, \", project file: \", openFiles[fileuri].projectFile, \", dirtyfile: \", filestash\n let diagnostics = getNimsuggest(fileuri).chk(uriToPath(fileuri), dirtyfile = filestash)\n debugEcho \"Got diagnostics: \",\n diagnostics[0..(if diagnostics.len > 10: 10 else: diagnostics.high)],\n (if diagnostics.len > 10: \" and \" & $(diagnostics.len-10) & \" more\" else: \"\")\n if diagnostics.len == 0:\n notify(\"textDocument/publishDiagnostics\", create(PublishDiagnosticsParams,\n fileuri,\n @[]).JsonNode\n )\n else:\n var response: seq[Diagnostic]\n for diagnostic in diagnostics:\n if diagnostic.line == 0:\n continue\n\n if diagnostic.filePath != uriToPath(fileuri):\n continue\n # Try to guess the size of the identifier\n let\n message = diagnostic.nimDocstring\n endcolumn = diagnostic.column + message.rfind('\\'') - message.find('\\'') - 1\n response.add create(Diagnostic,\n create(Range,\n create(Position, diagnostic.line-1, diagnostic.column),\n create(Position, diagnostic.line-1, max(diagnostic.column, endcolumn))\n ),\n some(case diagnostic.forth:\n of \"Error\": DiagnosticSeverity.Error.int\n of \"Hint\": DiagnosticSeverity.Hint.int\n of \"Warning\": DiagnosticSeverity.Warning.int\n else: DiagnosticSeverity.Error.int),\n none(int),\n some(\"nimsuggest chk\"),\n message,\n none(seq[DiagnosticRelatedInformation])\n )\n notify(\"textDocument/publishDiagnostics\", create(PublishDiagnosticsParams,\n fileuri,\n response).JsonNode\n )\n else:\n debugEcho \"Got unknown notification message\"\n continue\n except UriParseError as e:\n debugEcho \"Got exception parsing URI: \", e.msg\n continue\n except IOError as e:\n debugEcho \"Got IOError: \", e.msg\n break\n except CatchableError as e:\n debugEcho \"Got exception: \", e.msg\n continue\n"}}}
  31.  
  32.  
  33. Unable to parse data as RequestMessage
  34.  
  35. Got valid Notification message of type textDocument/didOpen
  36.  
  37. New document opened for URI: file:///home/arjun/Documents/sources/nimlsp/src/nimlsp.nim saving to /tmp/nimlsp/00000000874179EC.nim
  38.  
  39. Initialising project with /home/arjun/Documents/sources/nimlsp/src/nimlsp.nim:/home/arjun/.choosenim/toolchains/nim-1.4.0
  40.  
  41. Trying to read frame
  42.  
  43. Got frame:
  44. {"jsonrpc":"2.0","method":"textDocument/completion","params":{"textDocument":{"uri":"file:///home/arjun/Documents/sources/nimlsp/src/nimlsp.nim"},"position":{"line":11,"character":5},"context":{"triggerKind":1}},"id":46}
  45.  
  46.  
  47. Got valid Request message of type textDocument/completion
  48.  
  49. Got request for URI: file:///home/arjun/Documents/sources/nimlsp/src/nimlsp.nim copied to /tmp/nimlsp/00000000874179EC.nim
  50.  
  51. Running equivalent of: sug /home/arjun/Documents/sources/nimlsp/src/nimlsp.nim;/tmp/nimlsp/00000000874179EC.nim:12:5
  52.  
  53. Found suggestions: @[(section: ideSug, symKind: skProc, qualifiedPath: strutils.isEmptyOrWhitespace, forth: proc (s: string): bool{.noSideEffect, gcsafe, locks: 0.}, filePath: /home/arjun/.choosenim/toolchains/nim-1.4.0/lib/pure/strutils.nim, line: 2987, column: 5, doc: Checks if `s` is empty or consists entirely of whitespace characters., quality: 0, line: 2987, prefix: Prefix)]
  54.  
  55. Trying to read frame
  56.  
  57. Got frame:
  58. {"jsonrpc":"2.0","method":"$/cancelRequest","params":{"id":46}}
  59.  
  60.  
  61. Unable to parse data as RequestMessage
  62.  
  63. Got valid Notification message of type $/cancelRequest
  64.  
  65. Got unknown notification message
  66.  
  67. Trying to read frame
  68.  
  69. Got frame:
  70. {"jsonrpc":"2.0","method":"textDocument/completion","params":{"textDocument":{"uri":"file:///home/arjun/Documents/sources/nimlsp/src/nimlsp.nim"},"position":{"line":11,"character":5},"context":{"triggerKind":1}},"id":47}
  71.  
  72.  
  73. Got valid Request message of type textDocument/completion
  74.  
  75. Got request for URI: file:///home/arjun/Documents/sources/nimlsp/src/nimlsp.nim copied to /tmp/nimlsp/00000000874179EC.nim
  76.  
  77. Running equivalent of: sug /home/arjun/Documents/sources/nimlsp/src/nimlsp.nim;/tmp/nimlsp/00000000874179EC.nim:12:5
  78.  
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement