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

Ctrl-clicking a query method should navigate to the SQL query rather than the generated interface #1594

Closed
angusholder opened this issue Feb 13, 2020 · 22 comments · Fixed by #1598

Comments

@angusholder
Copy link
Contributor

angusholder commented Feb 13, 2020

Much like how Android's new ViewBinding classes are well integrated with the XML layouts, such that ctrl-clicking a view binding field goes to the XML element for that view, and ctrl-clicking the element ID lists usages of the view binding field

@AlecKazakova
Copy link
Collaborator

this should work. what ide/version are you using?

@angusholder
Copy link
Contributor Author

angusholder commented Feb 13, 2020

Android Studio 3.5.3 with SqlDelight library+IDE plugin+Gradle plugin 1.2.2 and Kotlin plugin 1.3.61

@AlecKazakova
Copy link
Collaborator

that should work....hmmm. If you restart the IDE does it start working again?

@angusholder
Copy link
Contributor Author

No, still the same

@AlecKazakova
Copy link
Collaborator

whats your sqldelight block of build.gradle look like in the effected module?

@angusholder
Copy link
Contributor Author

This is the top of my app module's build.gradle

buildscript {
	repositories {
		google()
		// Used to fetch wire-compiler
		mavenCentral()
	}

	dependencies {
		classpath 'com.squareup.wire:wire-compiler:2.2.0'
		classpath 'com.squareup.sqldelight:gradle-plugin:1.2.2'
	}
}

plugins {
	id 'com.android.application'
	id 'kotlin-android'
	id 'kotlin-android-extensions'
}
apply plugin: 'com.squareup.sqldelight'

sqldelight {
	// Database name
	Database {
		// Package name used for the generated MyDatabase.kt
		packageName = "foo.data.disk"

		// An array of folders where the plugin will read your '.sq' and '.sqm'
		// files. The folders are relative to the existing source set so if you
		// specify ["db"], the plugin will look into 'src/main/db'.
		// Defaults to ["sqldelight"] (src/main/sqldelight)
		sourceFolders = ["sqldelight"]

		// The directory where to store '.db' schema files relative to the root
		// of the project. These files are used to verify that migrations yield
		// a database with the latest schema. Defaults to null so the verification
		// tasks will not be created.
		schemaOutputDirectory = file("src/main/sqldelight/databases")
	}
}

There's only the android{} and dependencies{} blocks below

@angusholder
Copy link
Contributor Author

I did wonder about that apply plugin, I couldn't get it to work inside the plugins{} block

@AlecKazakova
Copy link
Collaborator

i dont think that should effect things

what does your modules file under .idea/sqldelight/ look like?

@angusholder
Copy link
Contributor Author

This is .idea/sqldelight/app/.sqldelight

{"databases":[{"packageName":"foo.data.disk","compilationUnits":[{"name":"debug","sourceFolders":[{"path":"src/debug/sqldelight","dependency":false},{"path":"src/main/sqldelight","dependency":false}]},{"name":"release","sourceFolders":[{"path":"src/main/sqldelight","dependency":false},{"path":"src/release/sqldelight","dependency":false}]}],"outputDirectory":"build\\generated\\sqldelight\\code\\Database","className":"Database","dependencies":[]}]}

@angusholder
Copy link
Contributor Author

Could it be a path separator issue? Do you run Windows?

@AlecKazakova
Copy link
Collaborator

ha, yea could definitely be a path separator issue. I use mac

@AlecKazakova
Copy link
Collaborator

https://github.com/cashapp/sqldelight/blob/master/sqldelight-idea-plugin/src/main/kotlin/com/squareup/sqldelight/intellij/SqlDelightGotoDeclarationHandler.kt

thats the code that should perform this action. Its possible to debug the running intellij instance by adding the jvm debug options to IntelliJ's custom vm options. If theres nothing immediately obvious with windows paths we'll probably have to do that and step through the code manually to see where its failing

i also put in a fix somewhat recently related to how intellij sometimes sets up modules for source sets, you can try the latest snapshot version of the intellij plugin to see if that fixes things: https://plugins.jetbrains.com/plugin/8191-sqldelight/update/78114

@angusholder
Copy link
Contributor Author

I tried the snapshot but nothing has changed.

Just to confirm, ctrl-clicking the query method navigates to the generated interface, instead of the SQL query, and ctrl-clicking the SQL query name says "No usages found in All Places"

@AlecKazakova
Copy link
Collaborator

yea those are both unexpected behaviors, at least on my end goto and find usages works

@angusholder
Copy link
Contributor Author

Oo I just got a error notification in Android Studio, it gives a stacktrace:

java.io.IOException: Invalid file name: 'build\generated\sqldelight\code\Database'
at com.intellij.openapi.vfs.newvfs.impl.VirtualFileSystemEntry.validateName(VirtualFileSystemEntry.java:274)
at com.intellij.openapi.vfs.newvfs.impl.VirtualFileSystemEntry.createChildDirectory(VirtualFileSystemEntry.java:268)
at com.squareup.sqldelight.intellij.util.GeneratedVirtualFile.getOrCreateDirectory(GeneratedVirtualFile.kt:62)
at com.squareup.sqldelight.intellij.util.GeneratedVirtualFile.getOrCreateDirectory(GeneratedVirtualFile.kt:67)
at com.squareup.sqldelight.intellij.util.GeneratedVirtualFile.getOrCreateDirectory(GeneratedVirtualFile.kt:67)
at com.squareup.sqldelight.intellij.util.GeneratedVirtualFile.getOrCreateDirectory(GeneratedVirtualFile.kt:67)
at com.squareup.sqldelight.intellij.util.GeneratedVirtualFile.getOrCreateDirectory(GeneratedVirtualFile.kt:67)
at com.squareup.sqldelight.intellij.util.GeneratedVirtualFile.getOrCreateFile(GeneratedVirtualFile.kt:55)
at com.squareup.sqldelight.intellij.util.GeneratedVirtualFile.getValue(GeneratedVirtualFile.kt:40)
at com.squareup.sqldelight.intellij.lang.SqlDelightFileViewProvider$generateSqlDelightCode$2$1.invoke(SqlDelightFileViewProviderFactory.kt:126)
at com.squareup.sqldelight.intellij.lang.SqlDelightFileViewProvider$generateSqlDelightCode$2$1.invoke(SqlDelightFileViewProviderFactory.kt:60)
at com.squareup.sqldelight.core.compiler.SqlDelightCompiler.writeTableInterfaces$sqldelight_compiler(SqlDelightCompiler.kt:116)
at com.squareup.sqldelight.core.compiler.SqlDelightCompiler.writeInterfaces(SqlDelightCompiler.kt:40)
at com.squareup.sqldelight.intellij.lang.SqlDelightFileViewProvider$generateSqlDelightCode$2.run(SqlDelightFileViewProviderFactory.kt:124)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1055)
at com.squareup.sqldelight.intellij.lang.SqlDelightFileViewProvider.generateSqlDelightCode(SqlDelightFileViewProviderFactory.kt:122)
at com.squareup.sqldelight.intellij.lang.SqlDelightFileViewProvider.access$generateSqlDelightCode(SqlDelightFileViewProviderFactory.kt:60)
at com.squareup.sqldelight.intellij.lang.SqlDelightFileViewProvider$contentsSynchronized$1$1.run(SqlDelightFileViewProviderFactory.kt:94)
at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:315)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.doRun(LaterInvocator.java:435)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.runNextEvent(LaterInvocator.java:419)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:403)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:764)
at java.awt.EventQueue.access$500(EventQueue.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:715)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:734)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:757)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:706)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:375)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

@AlecKazakova
Copy link
Collaborator

yup this looks like bad code for windows: https://github.com/cashapp/sqldelight/blob/master/sqldelight-idea-plugin/src/main/kotlin/com/squareup/sqldelight/intellij/util/GeneratedVirtualFile.kt#L59

wanna take a shot at fixing? Will be better so you can verify on your end. Theres a gradle task ./gradlew buildPlugin which outputs a new plugin .zip in sqldelight-idea-plugin/build/outputs (i think) which you can install from intellij

@angusholder
Copy link
Contributor Author

Sure, I'll take a look

@angusholder
Copy link
Contributor Author

angusholder commented Feb 13, 2020

How do I attach a debugger to Android Studio? Currently when I do it, the whole UI stops responding even though the debugger hasn't hit a breakpoint or anything, so I'm not able to attempt clicking Find Usages to trigger my breakpoint.

I'm not too familiar with manually putting a JVM into debug mode, I tried adding -Xdebug -Xrunjdwp:transport=dt_socket,address=1000,server=y,suspend=n to studio64.exe.vmoptions but it behaved the same.

@AlecKazakova
Copy link
Collaborator

I think that's right, you might want suspend=y and then force quit/reopen AS - it'll do nothing and then start up once you remote attach from intellij

@angusholder
Copy link
Contributor Author

When I attach to the AS process, its UI freezes up and the IntelliJ debugger shows up as if I'm at a breakpoint like this. Changing to suspend=y hasn't caused it to pause for a debugger on startup

image

@AlecKazakova
Copy link
Collaborator

O_o thats bizarre. Does your remote attach configuration differ at all from mine:

Screen Shot 2020-02-13 at 1 11 56 PM

another alternative is to debug this using the sqldelight gradle task. You can do ./gradlew runIde --debug-jvm from the command line and then attach a debugger from intellij. It wont be in android studio, it'll be a new sandbox idea, but you should be able to open your android project and reproduce the bug.

@angusholder
Copy link
Contributor Author

Okay I managed to debug using runIde thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants