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

Detect/suggest correct Clojure filetype #904

Closed
danielcompton opened this issue May 26, 2015 · 13 comments
Closed

Detect/suggest correct Clojure filetype #904

danielcompton opened this issue May 26, 2015 · 13 comments
Labels
released Marks issues which have had the fixes released in a stable build
Milestone

Comments

@danielcompton
Copy link
Collaborator

Part the first

In a hybrid clj/cljs project, when I create a new namespace in the ClojureScript section of the source paths, Cursive suggests making a .clj file, not .cljs. I can imagine improving this by adding a few heuristics to guess the filetype like:

  • Use whatever Kind the user last selected (perhaps scoped to this source path)
  • Suggesting file type that majority of sibling files are
  • If a previous source path is /clj or /cljs then choosing that
  • Looking at :cljsbuild/project.clj settings (I'm using bare clojurescript build scripts so this wouldn't apply in my case)
  • If Cursive can't figure it out then just defaulting to .clj (as it seems to now)
  • Perhaps other heuristics too

It's quite possible I'm doing something wrong and this is meant to be automatic, I checked the docs and couldn't see anything about it though. There's also lots of ambiguity and dynamicism in how people structure projects so this might be too complex. Also it's a pretty minor point.


Part the second

The other possibility would be to detect when people intend a cljs file to be created from the extension. Currently if I type

screenshot of intellij idea 27-05-15 10 00 33 am

I get

screenshot of intellij idea 27-05-15 10 00 48 am

If Cursive just detected that I typed .cljs it could change the Kind to ClojureScript, but people could change it back if they actually wanted handlers/cljs.clj.


Part the third

I'm also aware that up and down arrows change the type and maybe I should just use them instead :)

@cursive-ide
Copy link
Owner

I like the defaulting rules - they make sense. It might take me a while to get to them, though!

I'm not so keen on part II, since the idea is that the user enters the namespace's name, not the filename. This is why you get the namespace called clj.

And yes, up/down work nicely here :-)

@danielcompton
Copy link
Collaborator Author

I only suggested part II because when you type myns.cljs with a ClojureScript filetype then Cursive/IntelliJ creates myns.cljs, not myns/cljs.cljs. So I thought you could extend the same logic slightly further to detecting a likely filetype.

screenshot of intellij idea 27-05-15 4 28 47 pm

screenshot of intellij idea 27-05-15 4 28 55 pm

@hansgru
Copy link

hansgru commented May 27, 2015

IMHO part II is a bug since it is not how IntelliJ behaves. In a Web project, "New/Html File" and enter in the name filed test.html won't generate a directory like test/html.html or won't create test.html.html

@cursive-ide
Copy link
Owner

That's because it's creating a file, not a namespace. If you create a new Java class, you don't enter ClassName.java, just ClassName.

@hansgru
Copy link

hansgru commented May 28, 2015

@cursiveclojure

That's because it's creating a file, not a namespace. If you create a new Java class, you don't enter ClassName.java, just ClassName.

It doesn't matter, IntelliJ behaves intelligently here too: if I type however ClassName.java IntelliJ will correctly create only ClassName.java and not ClassName.java.java nor ClassName/java.java

@cursive-ide
Copy link
Owner

Right, but that is unambiguous. If I add logic like that, it will be impossible to create a namespace ending in a clj, cljs, cljx, cljc or edn segment.

@hansgru
Copy link

hansgru commented May 28, 2015

Right, but that is unambiguous. If I add logic like that, it will be impossible to create a namespace ending in a clj, cljs, cljx, cljc or edn segment.

IMHO since Cursive is an IntelliJ plug-in, it should behave like the rest of IntelliJ. In Java and other plug-ins is also not possible this way.
However there's a distinction, since there's "create package" that will just create directory structures for Java.

It would be better to separate stuff, with Menus items like:

  • "New/Clojure Namespace" to behave exactly like "create package", so no File creation.
  • "New/Clojure File" to behave like "New/Java Class"
  • "New/Clojure Script File"

@cursive-ide
Copy link
Owner

In Java it's very uncommon to create a class called java. In Clojure it's common to create a namespace ending in these suffixes - see clojure.edn from the standard library, for example. Cursive also contains numerous examples.

The problem with what you're suggesting is that there isn't a distinction between a namespace and a file (a namespace filesystem sequence ends in a file, unlike a package which is represented by a directory). There is also no distinction between a Clojure script file and a standard Clojure file. The only difference I can imagine needing there is the ability to create a Clojure file with no namespace at all.

Either way, I'm not going to add confusing options just to maintain a very minor consistency point with IntelliJ. The current functionality allows everything to be done in an intuitive way - this issue is just to provide some more sensible defaulting (which I think is a good idea).

@danielcompton
Copy link
Collaborator Author

Sounds good to me 👍

@mmower
Copy link

mmower commented May 30, 2016

If this is complicated to implement properly an 80% solution to my mind would be to just remember the last type used. Yes it will be wrong sometimes but in my experience I am mostly writing one type so the number of mistakes likely wouldn't increase but 80% of the time it would be right after the first time. Just a thought.

@danielcompton
Copy link
Collaborator Author

I agree with @mmower, probably 80%+ of my ClojureScript files start life as Clojure files until I realise I've created the wrong type.

@mmower
Copy link

mmower commented Nov 13, 2016

Is there any progress on this issue?

I've just hit yet another bug that was simply that I ended up creating a CLJ file in my CLJS project.

It really drives you mad and is, for me, the main chafing point using Cursive.

I realise there's lots of other stuff you want to do but this doesn't seem such a difficult issue to come up with an 80% solution and it's been almost a year and a half that people have been dealing with it.

@cursive-ide cursive-ide added this to the 1.4.0-eap5 milestone Nov 15, 2016
@cursive-ide
Copy link
Owner

This is fixed for the next build. Here's how this works:

  1. If the source root containing the new namespace contains "cljs" or "cljc", that extension is used.
  2. If all Clojure files under the source root are of the same type, that type is used.
  3. If a Clojure file has been created under the source root previously, the previous extension is used (scoped to the source root).
  4. Otherwise, clj is used.

IntelliJ actually automatically removes the file extension corresponding to the file template. What this means is that if you create a Clojure namespace with a name ending in .clj, that will be removed. But if you create a Clojure namespace with a name ending in .cljs, it will not since the extensions don't match. Unfortunately for boring internal reasons the extension cannot be used for defaulting the file type to create.

@cursive-ide cursive-ide added the released Marks issues which have had the fixes released in a stable build label Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released Marks issues which have had the fixes released in a stable build
Projects
None yet
Development

No branches or pull requests

4 participants