Auto reference d.ts files downloaded by intelliJ - intellij-idea

I started creating a Test-Project for playing around with TypeScript in intelliJ IDEA 14. At first I added the angularjs_DefinitelyTyped TypeScript libraries in the Settings (Settings / Language & Frameworks / JavaScript / Libraries -> Download... -> TypeScript community stubs). At this point IntelliJ gave me the desired code-completition. I started creating a Controller as described here. Everything works fine.
The Problem I stumbled over occurs, when I installed the TypeScript transpiler with the "File Watchers"-Plugin as described in the IntelliJ IDEA 14 Web Help. Now I get the Error "error TS2304: cannot find name 'ng.'" when typing ... extends ng.IScope.
As i already downloaded the definition-Files I was hoping that the "File Watchers"-Plugin auto references these Files.
I tried manually referencing the these files but the TypeScript transpiler cannot resolve %userprofile%\.IntelliJIdea14\system\extLibs nor $USER_HOME$\....
Is there a solution without manually downloading and referencing all these Files in my Projects?
Does the tsc have an option to do this? I don't find anything about it.
Hope anybody can help me with this Problem ;-)

angularjs_DefinitelyTyped TypeScript libraries in the Settings (Settings / Language & Frameworks / JavaScript / Libraries -> Download... -> TypeScript community stubs).
That is how IntelliJ supports Type definitions for JavaScript projects. For TypeScript projects you need to include + reference the .d.ts files manually. TIP: create a vendor.d.ts file or use TSD : https://github.com/DefinitelyTyped/tsd/ it will create a reference tsd.d.ts file for you for all your imports

Related

IntelliJ shows decompiled .class file instead of source code

I am having issues with IntelliJ - it shows me a "decompiled" version of the class instead of its source code if I ctrl+click the class.
This is what I see:
I am trying to open regular JDK source files.
The most relevant issue I found is explained here: Java sources replaced by decompiled files in Intellij
The most detailed answer I've found so far is there as well.
Yet it doesn't work for me:
Bytecode Viewer plugin is off.
Java Bytecode Decompiler plugin is off.
Platform, Project and Module all have same JDK version setup.
I have two JDKs available in IntelliJ: jdk1.8.0_161 and jbsdk8u112b287.2_windows_x86 (bundled with IntelliJ, but comes without src.zip). Tried with both (had to specify src.zip of jdk1.8.0_161 for jbsdk8u112b287.2_windows_x86) - no luck
src.zip is not corrupt - I can open it via WinRAR
When added jdk1.8.0_161 to IntelliJ, it automatically found src.zip. When manually adding src.zip to jbsdk8u112b287.2_windows_x86 Sourcepath tab - it started "Scanning for roots", but warned me that it "cannot determine what kind of files the chosen items contain" and offered me to "attach them as 'Sources'" so I agreed.
Tried File > Invalidate Caches / Restart... - same result.
Same issue in 2017.3 and fresh 2018.1 versions of IntelliJ.
Providing path for Documentation makes IntelliJ look for the documentation in the path specified. So it works as it should for both of JDKs. But not for sources.
Everything else works/compiles properly.
My settings:
1. Get the source files
Make sure you have downloaded and installed the source files of the JDK.
I'm on Arch Linux and installed them with pacman -S openjdk8-src which put a src.zip into /usr/lib/jvm/java-8-openjdk/. We'll use that zip file in the next step.
To list source packages of different JDK versions, do pacman -Ss "openjdk.*-src".
See this question on how to get the source files for your specific platform.
2. Point IntelliJ to the source files
In your module settings (open them with F4) under "Platform Settings" → "SDKs" → "Sourcepath", add the zip file containing the JDK source to your project JDK (be sure to pick the right JDK if IntelliJ lists more than one JDK) using the button with the plus sign:
3. Jump into the source
Select a JDK class, like Comparator, using IntelliJ's Search Everywhere or Ctrl+b with the cursor on the name of the class.
I also have the same problem. The problem for my case is that Project SDK is set to 13 [Invalid]. After I can Project SDK to a valid SDK. My problem is solved.
I tried all the things mentioned at other places for this but at the end I was doing a silly mistake. Intellij was pointing to JDK 11 for which there was no source code (I had both the SDKs 8 & 11). I removed JDK 11 and pointed to JDK 8. JDK had the source code, thus now I can see the source code on ctrl click. Also, I had disabled the bytecode viewer and decompiler plugins. Hope this helps some one.
This also happens for large files - IDEA decides to decompile them instead if indexing sources, which can take ages.
If you're willing to accept the drawdown, adding the following in Help | Edit Custom Properties might fix the problem:
idea.max.intellisense.filesize=4096
On ubuntu there was java version “OpenJDK” when I changed to “Oracle Java”, the error went away and javadoc returned
I meet same problem and finally it gone after I copy JDK to another folder and change config in IntelliJ. I think maybe cause there is a space in path before, because it is installed under "Program Files" folder.
For downloading the source code of class files belong to jar you can use download source option present on top right corner in the de-compiled class file.
On my Windows 10, expand maven:
For me going to File -> Project Structure -> Project -> SDK -> Add SDK -> Download JDK and selecting Oracle OpenJDK solved the problem. Prior to that I had a different JDK selected and apparently it didn't include source code
If you are in a maven project make sure in the project structure all the complied folders are in the excluded section.
I suggest to use Linux Instead of windows. It's easy to find and download Java.
If you are using Linux, you can download SDKMAN
Install Java by SDKMAN
# find version
$ sdk list java
# download
$ sdk install java x.y.z-amzn
ctrl+alt+shift+s add JDK
Switch project JDK
If you are using maven , Right click on Project explorer -> choose Maven -> chick on "reload projects"
This did the trick for me:
Make sure you select the option "Project Files" (instead e.g. "Project").

SBT compilation for play framework 2.x disabled by default

I created a new Play Framework project using the activator, activator new my-project-name and then I selected the play-java template and the project is created with no errors.
Then I import the project into my IDE, IntelliJ, as a SBT project. When the project is imported a popup is shown saying: SBT compilation for play framework 2.x disabled by default.
On IntelliJ project's panel it doesn't show all (mostly the files with the code) files. Just a handful of them.
The build.sbt file looks like full of compilation error (pretty much all the lines are red underlined).
Here's the build.sbt file
name := """my-project-name"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs
)
// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator
fork in run := true
I can compile and run the code with activator ui with no errors. So, why isn't IntelliJ fully importing the project and it shows me SBT compilation for play framework 2.x disabled by default message?
I googled around and couldn't find any hint related to this so I'm kinda lost here.
EDIT: -------------------------------------
I closed the project on IntelliJ and deleted the project folder. Closed IntelliJ and using activator I created again the same project. Using activator ui I compiled the project. Then I fired up IntelliJ and was prompted to either open a project, create a new one or import a project.
Selected import a project and did the normal "import a project steps" and IntelliJ imported the project with no hassle. But if I try to import the project while with an open project on IntelliJ I get the same problem that lead me to make this question. Maybe this is a bug on IntelliJ?
EDIT 2 ------------------------------------------
The solution to these two problems (the "SBT compilation for play framework 2.x disabled by default" and the files not showing on IntelliJ) can be fixed with user3384225 and DarkShadow answers.
Preferences > Languages & Frameworks > Play2
Under 'Compiler' enable 'Use Play 2 compiler for this project'
I Stumbled upon this problem myself when configuring play framework for IntelliJ IDEA IDE (version: 2017.3). I overcame this problem by following the steps below.
Navigate to:
File --> Settings --> Languages and Frameworks --> Play2 --> Compiler tab
and inside the compiler tab:
put a tick to the Use Play2 compiler for this project
Hope this helped.
Similar answer to user3384225's answer was posted here:
https://devnet.jetbrains.com/message/5560914
They say:
Settings -> Langauges & Frameworks -> Play2 -> Compiler -> User Play 2 compiler for this project
I am also a newbie and was facing the same problem till yesterday. Probably you are trying to open the project through File->open.
Try the steps below:-
File->New->Project from existing source->select the build.sbt from the project you created using the activator->Import project from external model and select SBT from the options->OK.
It will take some time to import files and to create the settings required for intellij idea project.
I am using intellij idea 14.1.5. It worked for me hope it will for you also.
For current projects, you can fix this by using File->Invalidate Caches/Restart..
Most probably you have solved you problem, but just to help others
What you just have to do is -> check the option "Use Play 2 compiler for this project" given under Preferences -> Languages & Frameworks -> Play2 -> Compiler
Close the project and then import the project as sbt project.
Intellij will automatically dump and index the project dependancies.
Stumbled upon the same problem today. Solved by wiping the ~/.IntelliJIdea14 directory. Unfortunately any other things I've tried didn't help.
Just use: File->New->Project from existing source->select the build.sbt from the project you created using the activator->ok.
and it's done.

Play Framework 2.4 and IntelliJ Idea

I am trying to open a play 2.4 project in IntelliJ but since things have changed I don't know how to do this.
In previous versions I could just run
activator idea
Or use the activator UI and click on generate intelliJ project, but in 2.4 the idea command doesn't seem to exist
[error] Not a valid command: idea (similar: eval, alias)
[error] Not a valid project ID: idea
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: idea (similar: clean)
[error] idea
[error] ^
And the UI seems broken, when I click on generate intelliJ project it tries to compile the app and gives this error:
play/Play$
java.lang.NoClassDefFoundError: play/Play$
Use 'last' for the full log.
Failed to load project.
I created the project from scratch using the play java template with:
activator new
I have also tried importing the folder as a project but intelliJ doesn't seem to identify it as a project
I run into the same problem, as I used IDEA to open a project folder, it had an play 2 app in a sub folder, then I import module (play 2 app) to the system.
And it works well.
After that I have changed the module folder name, then when I run the app, it displayed:
Not a valid project ID: "project team"
I re-checked the folder, and found that in the File -> Project Structure option, the name of module is "root", and the "team" is the module for whole project (not the module imported by SBT), so apparently, the module wasn't functional after I changed the module folder name.
So I found and removed all .idea folder, which is IDEA configureation, then re-open/re-import the module, still not work. I thought it's IDEA cache issue, it do have cache for the opened project, so I changed the project folder from team to something else, clean the .idea folders, and re-open/re-import it. It worked.
If the play app is in the project folder as a sub folder, to import the module at File -> Project Structure.
The project name should be "root" when running it in IDEA. So in this case, you should rename "project team" to "root" in the name field.
Solution 1
In my case (IDEA 2018.2), I changed the lazy val variable in build.sbt, it had the name "root" when my project name was "top", changed "root" to "top".
Before:
lazy val root = (project in file(".")).enablePlugins(PlayScala)
After:
lazy val top = (project in file(".")).enablePlugins(PlayScala)
Change project variable
Solution 2
The method proposed by Tom solved my problem partially, because after rebooting the IDEA I returned the project name back, it was necessary to change the variable from "top" to "root" in build.sbt.
Before:
name: = "top"
After:
name := "root"
Intellij IDEA lets you quickly create a Play application without using a command prompt. You don’t need to configure anything outside of the IDE, the SBT build tool takes care of downloading appropriate libraries, resolving dependencies and building the project.
Before you start creating a Play application in IntelliJ IDEA, make sure that the latest Scala Plugin is installed and enabled in IntelliJ IDEA. Even if you don’t develop in Scala, it will help with the template engine and also resolving dependencies.
Basically, install Play Framework, Scala plugins and import project into Intellij as SBT project. Don't use activator to create IDEA project files. More details here.
It seems I had not updated scala/sbt to the latest version in intelliJ
Once I had done this it noticed that it was a valid project, though the docs don't seem to mention you can import it as an SBT project, just how to create it as a new sbt project (which I did not want to do as I wanted to create it via activator)
I also had the project/play-fork-run.sbt file issue
I use Intellij Idea 16.3.3 and this problem appears sometimes. How I fixed it? You just need to open your SBT plugin and under your project get the context menu then you should choose "Ignore SBT project". After a current process is finished you should turn on this option again. This is work for me:)

How can I manage a non-src module with intellij 13?

I recently switched from eclipse. With eclipse, I was used to have "non-src" projects (General->Simple Projects) in my workspace. They were pretty handy, since I could use them for version control of documentations, configure servers, ...)
Now with intellij, I am missing this feature. I only can import src modules into my project, otherwise I get the warning "nothing to import". Any idea how to trick intellij to accept a plain old file system directory?
Update:
To clarify, this is my setup:
root (trunk, sync with svn)
+- maven-project (root pom.xml)
|+- module a
|+- module b
|\- ...
+- documentation
|\- word/xls/...
\- server
\- jboss home dir
I sync (update) directly on "root" to keep everything together.
I imported the structure to intellij, but only got the "maven-project" (with all submodules), not "documentation" nor "server".
I would like to have the folders next to "maven-project" in my project structure. That way, I could easily edit server settings files within idea for example or add/commit new office files without using extra tools or cli.
Hope this helps to get the picture.
Unfortunately there is no kind of "Empty Module" or "Facet-less Module" in IntelliJ.
In such cases I just create a static "Web" project, as I think this is the least invasive type for modules, which doesn't need any facet:
File -> New Module
Static Web -> Web
At "Content Root" -> Point to your sources
Can you bypass the import feature and just create a new module, and then copy the contents in there?
Otherwise, do you really need a module at all? Folders can quite happily sit in the file structure of your intellij project without being modules.

IntelliJ IDEA and PlayFramework modules

After a lot of good comment about IDEA, I decided to give it a try. I downloaded the Community Edition and would like to use it for PlayFramework development.
I have followed official documentation and some other information gathered around, but I have not succeeded completely. When using a project with differents (play) modules, the different classes are not found.
For example when using Secure module, IDEA keeps complaining about not finding Secure.class. It has to be a classpath issue. I tried to attach Java source & classes ($PLAY/modules/secure/) in module settings (F4), class is still not found. Did I miss something?
BTW, I have done a play dependencies and play idealize, which seems to add another module Secure into project in IDEA.
Thanks,
The answer is to run the following:
play deps
play idealize
This forces the IDEA .iml project file to be refreshed with the updated class path entries for the new module (in this case Secure).
A issue I came across using IntelliJ and Playframework.
The log4j.properties file or log4j.xml file are not in classpath by default. You have to add the conf as a source folder in module settings.
You need to add the Secure module you have created in IDEA as a dependency to the main application module:
Go to File -> Project Structure
Choose the main module
Choose the Dependencies tab
Click Add -> Module Dependency
Choose the IDEA Module you created for the Play Secure module
Also make sure you have the correct source path selected for the Secure module in IDEA.