nim-lang / nimsuggest

idetools for the nim language
MIT License
42 stars 9 forks source link

nimscript file is executed when editor opens the file with nimsuggest #29

Closed yuutayamada closed 8 years ago

yuutayamada commented 8 years ago

I made sure this behavior in major-restructure branch, but I think it could be happened in master branch too. (because I copied Araq's code from master to major-restructure branch)

foo.nims:

mkdir "bar"

When I opened above file named foo.nim with Emacs using nimsuggest, bar directory was created.

I suspect this part is cause of this bug: https://github.com/nim-lang/nimsuggest/blob/master/nimsuggest.nim#L420

but for some reasons my editor doesn't work in nimsuggest's master branch and I can't make sure...

yuutayamada commented 8 years ago

We use nimscript:

  1. .nims files
  2. .nimble files
  3. from #? shebang (please correct me if I'm wrong, I'm just guessing)
  4. Be used from other editors or IDEs extensions or something we don't expect. For example, in emacs, users can open a file with any programming mode if they have magic comment to near the end of file. (don't care the extension name)

We can support 1-3 in nimsuggest, but we can not support 4. (or difficult to maintain)

So, I'm hoping that (1) nimsuggest allow another option to avoid loading current dot nims file when editor or IDE called nimsuggest or (2) nimsuggest just allow empty argument as PROJECTNAME.nim for this case.

example

# we call nimsuggest like this and can not omit PROJECTNAME.nim
nimsuggest --port 6000 PROJECTNAME.nim

@Araq is there recommend way? does (1) or (2) look ok?

Araq commented 8 years ago

(3. no, the gangbang has nothing to do with it) I don't understand this issue. nimsuggest has to run the nimscript files to get the correct --path etc. If your nimscript file has a toplevel mkdir statement, that's a problem with the nim compiler too.

yuutayamada commented 8 years ago

If your nimscript file has a toplevel mkdir statement, that's a problem with the nim compiler too.

Please let me know proper usage of nimsuggest for nimscript files. I'm having a trouble using nimsuggest with my editor when emacs open nimscript file (emacs calls chk method of nimsuggest) Below code is official example of nimscript of standalone Nimscript and when I open the nims file of below content, emacs call nimsuggest for syntax check, which start git clone by just opening file.

mode = ScriptMode.Verbose

var id = 0
while dirExists("nimble" & $id):
  inc id

exec "git clone https://github.com/nim-lang/nimble.git nimble" & $id

withDir "nimble" & $id & "/src":
  exec "nim c nimble"

mvFile "nimble" & $id & "/src/nimble".toExe, "bin/nimble".toExe

I might wrongly implemented emacs' nim-mode because nimsuggest doesn't work without projectname.nim of last argument. What should I specify as projectname.nim when I want to check just a nimscript file for script usage? (currently Emacs specify current opening file's absolute path)

Araq commented 8 years ago

Checking of nims files is not supported at all for this reason. Again, this is not a nimsuggest specific problem.

yuutayamada commented 8 years ago

Thank you. I'll disable nimsuggest for nimscript files in emacs' nim-mode.