jonnyboyC / kos-language-server

A language server for the Kerboscript (kOS) a language for Kerbal Space Program
MIT License
27 stars 6 forks source link

Feature request check for global variables and functions #12

Closed Efratror closed 5 years ago

Efratror commented 5 years ago

I would love it if the server would be able to check for global variables and global functions that are written in an other script, for example lib files, when you put a runpath command in your main file.

I use lib scripts a lot to keep my main code readable but now I get a lot of variable might not be declared warnings.

Foo.ks

runpath("bar.ks")
DoSomeThing(). 

bar.ks
Function DoSomeThing{
Bla bla bla
}
jonnyboyC commented 5 years ago

This should in theory work already. What folder do you currently have vscode open in. Right now the behavior is that the open folder is considered 0: the archive directory. This and the other issue you reported are likely connected. Let me try to rule out there simply isn't a bug in the path resolving first.

I may also consider adding something akin to ksconifig.json and have that act as a marker for 0: if vscode is open in another directory.

Efratror commented 5 years ago

This "problem" isn't fixed with in release 0.3.0 looking at the output of vs-code it seems it doesn't check bar.ks at all.

[Server(11408) {"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"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":true},"configuration":true,"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":true},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true},"completionItemKind":{"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]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"]}},"definition":{"dynamicRegistration":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"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},"codeAction":{"dynamicRegistration":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"documentLink":{"dynamicRegistration":true},"typeDefinition":{"dynamicRegistration":true},"implementation":{"dynamicRegistration":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true}}}] Started and initialize received
[Server(11408) c:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program Modded\Ships\Script] Started and initialize received

Scanning file:///c%3A/Program%20Files%20%28x86%29/Steam/steamapps/common/Kerbal%20Space%20Program%20Modded/Ships/Script/foo.ks
Parsing file:///c%3A/Program%20Files%20%28x86%29/Steam/steamapps/common/Kerbal%20Space%20Program%20Modded/Ships/Script/foo.ks
Function resolving file:///c%3A/Program%20Files%20%28x86%29/Steam/steamapps/common/Kerbal%20Space%20Program%20Modded/Ships/Script/foo.ks
Resolving file:///c%3A/Program%20Files%20%28x86%29/Steam/steamapps/common/Kerbal%20Space%20Program%20Modded/Ships/Script/foo.ks
Type checking file:///c%3A/Program%20Files%20%28x86%29/Steam/steamapps/common/Kerbal%20Space%20Program%20Modded/Ships/Script/foo.ks

[Warn  - 08:39:36] Resolver encountered 1 Errors.
[Info  - 08:39:36] 
[Info  - 08:39:36] -------- performance ---------
[Info  - 08:39:36] Scanner took 0.725032 ms
[Info  - 08:39:36] Parser took 1.577766 ms
[Info  - 08:39:36] Function Resolver took 0.826892 ms
[Info  - 08:39:36] Resolver took 0.666141 ms
[Info  - 08:39:36] Type Checking took 1.186254 ms
[Info  - 08:39:36] ------------------------------

image

jonnyboyC commented 5 years ago

I'll try to replicate these results with a test repository, I'll link the the repo when I get a chance to get it up and running

jonnyboyC commented 5 years ago

I've done some testing and I have found the issue. Currently relative paths such as runpath("bar.ks") and absolute path such as runpath("0:\bar.ks") or runpath("0:/bar.ks") work.

It appears I didn't have a close enough reading of the documentation because I was unaware runpath("0:bar.ks") was a valid path in kos.

I'll need to push out another small release to get this fixed

jonnyboyC commented 5 years ago

Pr #16 should fix this issue. Let me know if this resolves the issue for you.