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

Support opening to line number in all JetBrains IDEs #454

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 14 additions & 42 deletions sources/iTermSemanticHistoryController.m
Original file line number Diff line number Diff line change
Expand Up @@ -207,24 +207,9 @@ - (NSString *)emacsClientInApplicationBundle:(NSBundle *)bundle {
return executable;
}

- (NSString *)intelliJIDEALauncherInApplicationBundle:(NSBundle *)bundle {
DLog(@"Trying to find IntelliJ IDEA launcher in %@", bundle.bundlePath);
return [[[[bundle.bundleURL URLByAppendingPathComponent:@"Contents"] URLByAppendingPathComponent:@"MacOS"] URLByAppendingPathComponent:@"idea"] path];
}

- (void)launchAppWithBundleIdentifier:(NSString *)bundleIdentifier args:(NSArray *)args {
NSBundle *bundle = [self applicationBundleWithIdentifier:bundleIdentifier];
if (!bundle) {
DLog(@"No bundle for %@", bundleIdentifier);
return;
}
NSString *executable = [self executableInApplicationBundle:bundle];
if (!executable) {
DLog(@"No executable for %@ in %@", bundleIdentifier, bundle);
return;
}
DLog(@"Launch %@: %@ %@", bundleIdentifier, executable, args);
[self launchTaskWithPath:executable arguments:args completion:nil];
args = [@[ @"-nb", bundleIdentifier, @"--args" ] arrayByAddingObjectsFromArray: args];
[self launchTaskWithPath:@"/usr/bin/open" arguments:args completion:nil];
}

- (void)launchVSCodeWithPath:(NSString *)path codium:(BOOL)codium {
Expand Down Expand Up @@ -286,27 +271,6 @@ - (void)launchEmacsWithArguments:(NSArray *)args {

}

- (void)launchIntelliJIDEAWithArguments:(NSArray<NSString *> *)args path:(NSString *)path {
NSBundle *bundle = [self applicationBundleWithIdentifier:kIntelliJIDEAIdentifier];
if (!bundle) {
DLog(@"Failed to find IDEA bundle");
return;
}
NSString *launcher = [self intelliJIDEALauncherInApplicationBundle:bundle];
if (!launcher) {
DLog(@"Failed to find launcher in %@", bundle);
if (path) {
DLog(@"Launch idea with path %@", path);
[self launchAppWithBundleIdentifier:kIntelliJIDEAIdentifier
path:path];
}
return;
}
[self launchTaskWithPath:launcher
arguments:args
completion:nil];
}

- (NSString *)absolutePathForAppBundleWithIdentifier:(NSString *)bundleId {
return [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:bundleId];
}
Expand Down Expand Up @@ -344,8 +308,11 @@ + (NSArray *)bundleIdsThatSupportOpeningToLineNumber {
kTextmateIdentifier,
kTextmate2Identifier,
kBBEditIdentifier,
kEmacsAppIdentifier,
kIntelliJIDEAIdentifier ];
kEmacsAppIdentifier ];
}

+ (NSArray *)bundleIdPrefixesThatSupportOpeningToLineNumber {
return @[ kJetBrainsIdentifierPrefix ];
}

- (void)openFile:(NSString *)path
Expand Down Expand Up @@ -414,7 +381,7 @@ - (void)openFile:(NSString *)path
[self launchEmacsWithArguments:args];
return;
}
if ([identifier isEqualToString:kIntelliJIDEAIdentifier]) {
if ([identifier hasPrefix:kJetBrainsIdentifierPrefix]) {
NSArray<NSString *> *args = @[];
if (path) {
if (lineNumber) {
Expand All @@ -423,7 +390,7 @@ - (void)openFile:(NSString *)path
args = @[ path ];
}
}
[self launchIntelliJIDEAWithArguments:args path:path];
[self launchAppWithBundleIdentifier:identifier args:args];
return;
}

Expand Down Expand Up @@ -730,6 +697,11 @@ - (void)openPath:(NSString *)cleanedUpPath
}

- (BOOL)canOpenFileWithLineNumberUsingEditorWithBundleId:(NSString *)appBundleId {
for (NSString* prefix in [self.class bundleIdPrefixesThatSupportOpeningToLineNumber]) {
if ([appBundleId hasPrefix:prefix]) {
return YES;
}
}
return [[self.class bundleIdsThatSupportOpeningToLineNumber] containsObject:appBundleId];
}

Expand Down
2 changes: 2 additions & 0 deletions sources/iTermSemanticHistoryPrefsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ extern NSString *kTextmate2Identifier;
extern NSString *kBBEditIdentifier;
extern NSString *kEmacsAppIdentifier;
extern NSString *kIntelliJIDEAIdentifier;
extern NSString *kIntelliJPyCharmIdentifier;
extern NSString *kJetBrainsIdentifierPrefix;

extern NSString *kSemanticHistoryBestEditorAction;
extern NSString *kSemanticHistoryUrlAction;
Expand Down
1 change: 1 addition & 0 deletions sources/iTermSemanticHistoryPrefsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
NSString *kVSCodeInsidersIdentifier = @"com.microsoft.VSCodeInsiders";
NSString *kEmacsAppIdentifier = @"org.gnu.Emacs";
NSString *kIntelliJIDEAIdentifier = @"com.jetbrains.intellij.ce";
NSString *kJetBrainsIdentifierPrefix = @"com.jetbrains.";

NSString *kSemanticHistoryBestEditorAction = @"best editor";
NSString *kSemanticHistoryUrlAction = @"url";
Expand Down