Skip to content

Commit 9c99034

Browse files
committed
Get current workspace simply.
1 parent d58c53a commit 9c99034

10 files changed

Lines changed: 104 additions & 8 deletions

SCXcodeSwitchExpander.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
18990B3618D2529C007A8756 /* SCXcodeSwitchExpander.m in Sources */ = {isa = PBXBuildFile; fileRef = 18990B3518D2529C007A8756 /* SCXcodeSwitchExpander.m */; };
1414
18A1B48118DDA742007CA06A /* IDEFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 18A1B48018DDA742007CA06A /* IDEFoundation.framework */; };
1515
18ECEB5718D267A0005F6C59 /* DVTTextCompletionController+SCXcodeSwitchExpander.m in Sources */ = {isa = PBXBuildFile; fileRef = 18ECEB5618D267A0005F6C59 /* DVTTextCompletionController+SCXcodeSwitchExpander.m */; };
16+
B150FD8A1CBBD7D200DFE4D8 /* DVTTextCompletionSession+SCXcodeSwitchExpander.m in Sources */ = {isa = PBXBuildFile; fileRef = B150FD891CBBD7D200DFE4D8 /* DVTTextCompletionSession+SCXcodeSwitchExpander.m */; };
1617
B18173D81CBB91E400995105 /* DVTSourceCodeLanguage+SCXCodeSwitchExpander.m in Sources */ = {isa = PBXBuildFile; fileRef = B18173D71CBB91E400995105 /* DVTSourceCodeLanguage+SCXCodeSwitchExpander.m */; };
1718
/* End PBXBuildFile section */
1819

@@ -42,6 +43,11 @@
4243
18A1B48018DDA742007CA06A /* IDEFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IDEFoundation.framework; path = ../../../../Applications/Xcode.app/Contents/Frameworks/IDEFoundation.framework; sourceTree = "<group>"; };
4344
18ECEB5518D267A0005F6C59 /* DVTTextCompletionController+SCXcodeSwitchExpander.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DVTTextCompletionController+SCXcodeSwitchExpander.h"; sourceTree = "<group>"; };
4445
18ECEB5618D267A0005F6C59 /* DVTTextCompletionController+SCXcodeSwitchExpander.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "DVTTextCompletionController+SCXcodeSwitchExpander.m"; sourceTree = "<group>"; };
46+
B107DD4D1CBBCBE7009D65E7 /* IDEWorkspaceWindowController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IDEWorkspaceWindowController.h; sourceTree = "<group>"; };
47+
B107DD4E1CBBCC94009D65E7 /* IDEEditorArea.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IDEEditorArea.h; sourceTree = "<group>"; };
48+
B107DD4F1CBBCD14009D65E7 /* IDEEditorContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IDEEditorContext.h; sourceTree = "<group>"; };
49+
B150FD881CBBD7D200DFE4D8 /* DVTTextCompletionSession+SCXcodeSwitchExpander.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DVTTextCompletionSession+SCXcodeSwitchExpander.h"; sourceTree = "<group>"; };
50+
B150FD891CBBD7D200DFE4D8 /* DVTTextCompletionSession+SCXcodeSwitchExpander.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "DVTTextCompletionSession+SCXcodeSwitchExpander.m"; sourceTree = "<group>"; };
4551
B18173D61CBB91E400995105 /* DVTSourceCodeLanguage+SCXCodeSwitchExpander.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DVTSourceCodeLanguage+SCXCodeSwitchExpander.h"; sourceTree = "<group>"; };
4652
B18173D71CBB91E400995105 /* DVTSourceCodeLanguage+SCXCodeSwitchExpander.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "DVTSourceCodeLanguage+SCXCodeSwitchExpander.m"; sourceTree = "<group>"; };
4753
B18173D91CBB92C700995105 /* DVTSourceCodeLanguage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DVTSourceCodeLanguage.h; sourceTree = "<group>"; };
@@ -77,13 +83,16 @@
7783
B18173DA1CBB958300995105 /* DVTTextStorage.h */,
7884
185293151B085C4200A2E2C7 /* DVTViewController.h */,
7985
0144D99F1B06F9F00012D7A2 /* IDEEditor.h */,
86+
B107DD4E1CBBCC94009D65E7 /* IDEEditorArea.h */,
87+
B107DD4F1CBBCD14009D65E7 /* IDEEditorContext.h */,
8088
0144D9B11B06FBD30012D7A2 /* IDEFileTextSettings.h */,
8189
0144D9A01B06F9F00012D7A2 /* IDEIndex.h */,
8290
0144D9A11B06F9F00012D7A2 /* IDEIndexCollection.h */,
8391
0144D9A21B06F9F00012D7A2 /* IDEIndexCompletionItem.h */,
8492
0144D9A31B06F9F00012D7A2 /* IDEIndexContainerSymbol.h */,
8593
0144D9A61B06F9F00012D7A2 /* IDEIndexSymbol.h */,
8694
B1F83C551CB9090F00843242 /* IDEWorkspace.h */,
95+
B107DD4D1CBBCBE7009D65E7 /* IDEWorkspaceWindowController.h */,
8796
);
8897
path = "Xcode Headers";
8998
sourceTree = "<group>";
@@ -123,6 +132,8 @@
123132
18990B3518D2529C007A8756 /* SCXcodeSwitchExpander.m */,
124133
18ECEB5518D267A0005F6C59 /* DVTTextCompletionController+SCXcodeSwitchExpander.h */,
125134
18ECEB5618D267A0005F6C59 /* DVTTextCompletionController+SCXcodeSwitchExpander.m */,
135+
B150FD881CBBD7D200DFE4D8 /* DVTTextCompletionSession+SCXcodeSwitchExpander.h */,
136+
B150FD891CBBD7D200DFE4D8 /* DVTTextCompletionSession+SCXcodeSwitchExpander.m */,
126137
B18173D61CBB91E400995105 /* DVTSourceCodeLanguage+SCXCodeSwitchExpander.h */,
127138
B18173D71CBB91E400995105 /* DVTSourceCodeLanguage+SCXCodeSwitchExpander.m */,
128139
18142E1D18E89497006BD329 /* Xcode Headers */,
@@ -202,6 +213,7 @@
202213
buildActionMask = 2147483647;
203214
files = (
204215
18ECEB5718D267A0005F6C59 /* DVTTextCompletionController+SCXcodeSwitchExpander.m in Sources */,
216+
B150FD8A1CBBD7D200DFE4D8 /* DVTTextCompletionSession+SCXcodeSwitchExpander.m in Sources */,
205217
18990B3618D2529C007A8756 /* SCXcodeSwitchExpander.m in Sources */,
206218
B18173D81CBB91E400995105 /* DVTSourceCodeLanguage+SCXCodeSwitchExpander.m in Sources */,
207219
);

SCXcodeSwitchExpander/DVTTextCompletionController+SCXcodeSwitchExpander.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#import "DVTSourceCodeSymbolKind.h"
2323
#import "DVTSourceTextView.h"
2424

25-
#import "DVTTextCompletionSession.h"
25+
#import "DVTTextCompletionSession+SCXcodeSwitchExpander.h"
2626

2727
#import <objc/objc-class.h>
2828

@@ -159,7 +159,7 @@ - (DVTSourceCodeLanguageKind)currentLanguage
159159
DVTSourceTextView *textView = (DVTSourceTextView *)self.textView;
160160
DVTTextStorage *textStorage = (DVTTextStorage *)textView.textStorage;
161161
DVTSourceCodeLanguage *language = textStorage.language;
162-
162+
163163
return language.kind;
164164
}
165165

@@ -228,7 +228,8 @@ @implementation DVTTextCompletionListWindowController (SCXcodeSwitchExpander)
228228

229229
- (BOOL)tryExpandingSwitchStatementForLanguage:(DVTSourceCodeLanguageKind)language
230230
{
231-
IDEIndex *index = [[[SCXcodeSwitchExpander sharedSwitchExpander] currentWorkspace] index];
231+
IDEWorkspace *workspace = self.session.currentWorkspace;
232+
IDEIndex *index = workspace.index;
232233

233234
if(index == nil) {
234235
return NO;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// DVTTextCompletionSession+SCXcodeSwitchExpander.h
3+
// SCXcodeSwitchExpander
4+
//
5+
// Created by Tomohiro Kumagai on 4/11/16.
6+
// Copyright © 2016 Stefan Ceriu. All rights reserved.
7+
//
8+
9+
#import "DVTTextCompletionSession.h"
10+
11+
@class IDEWorkspace;
12+
13+
@interface DVTTextCompletionSession (SCXcodeSwitchExpander)
14+
15+
/// Returns the workspace of the session.
16+
@property (readonly) IDEWorkspace *currentWorkspace;
17+
18+
@end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// DVTTextCompletionSession+SCXcodeSwitchExpander.m
3+
// SCXcodeSwitchExpander
4+
//
5+
// Created by Tomohiro Kumagai on 4/11/16.
6+
// Copyright © 2016 Stefan Ceriu. All rights reserved.
7+
//
8+
9+
#import "DVTTextCompletionSession+SCXcodeSwitchExpander.h"
10+
#import "IDEWorkspace.h"
11+
12+
@implementation DVTTextCompletionSession (SCXcodeSwitchExpander)
13+
14+
- (IDEWorkspace*)currentWorkspace
15+
{
16+
return [self.currentCompletionContext valueForKey:@"IDETextCompletionContextWorkspaceKey"];
17+
}
18+
19+
@end

SCXcodeSwitchExpander/SCXcodeSwitchExpander.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,4 @@
1919
/// This property is unavailable because language will be get from IDEEditor directly.
2020
@property (nonatomic, assign) BOOL isSwift NS_UNAVAILABLE;
2121

22-
/// Returns current workspace.
23-
@property(readonly) IDEWorkspace *currentWorkspace;
24-
2522
@end

SCXcodeSwitchExpander/SCXcodeSwitchExpander.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
#import "SCXcodeSwitchExpander.h"
1010
#import "IDEIndex.h"
1111
#import "IDEEditor.h"
12+
#import "IDEEditorArea.h"
13+
#import "IDEEditorContext.h"
1214
#import "IDEFileTextSettings.h"
1315
#import "IDEWorkspace.h"
16+
#import "IDEWorkspaceWindowController.h"
1417

1518
static SCXcodeSwitchExpander *sharedExpander = nil;
1619

@@ -63,8 +66,8 @@ - (void)indexDidChange:(NSNotification *)sender NS_UNAVAILABLE
6366
- (IDEWorkspace *)currentWorkspace
6467
{
6568
NSWindowController *currentWindowController = [[NSApp keyWindow] windowController];
66-
if ([currentWindowController isKindOfClass:NSClassFromString(@"IDEWorkspaceWindowController")]) {
67-
return [currentWindowController valueForKey:@"_workspace"];
69+
if ([currentWindowController isKindOfClass:[IDEWorkspaceWindowController class]]) {
70+
return [(IDEWorkspaceWindowController*)currentWindowController editorArea].lastActiveEditorContext.workspace;
6871
}
6972
else {
7073
return nil;

SCXcodeSwitchExpander/Xcode Headers/DVTTextCompletionSession.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
@interface DVTTextCompletionSession : NSObject
1313

14+
@property(readonly, nonatomic) NSDictionary *currentCompletionContext;
1415
@property(readonly) unsigned long long wordStartLocation;
1516
@property(readonly) DVTTextCompletionListWindowController *listWindowController;
1617
@property(readonly) DVTCompletingTextView *textView;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// IDEEditorArea.h
3+
// SCXcodeSwitchExpander
4+
//
5+
// Created by Tomohiro Kumagai on 4/11/16.
6+
// Copyright © 2016 Stefan Ceriu. All rights reserved.
7+
//
8+
9+
@class IDEEditorContext;
10+
11+
@interface IDEEditorArea : NSObject
12+
13+
@property(retain, nonatomic) IDEEditorContext *lastActiveEditorContext;
14+
15+
@end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// IDEEditorContext.h
3+
// SCXcodeSwitchExpander
4+
//
5+
// Created by Tomohiro Kumagai on 4/11/16.
6+
// Copyright © 2016 Stefan Ceriu. All rights reserved.
7+
//
8+
9+
@interface IDEEditorContext : NSObject
10+
11+
- (id)workspace;
12+
13+
@end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// IDEWorkspaceWindowController.h
3+
// SCXcodeSwitchExpander
4+
//
5+
// Created by Tomohiro Kumagai on 4/11/16.
6+
// Copyright © 2016 Stefan Ceriu. All rights reserved.
7+
//
8+
9+
#import <Cocoa/Cocoa.h>
10+
11+
@class IDEEditorArea;
12+
13+
@interface IDEWorkspaceWindowController : NSWindowController <NSWindowDelegate>
14+
15+
@property (readonly) IDEEditorArea *editorArea;
16+
17+
@end

0 commit comments

Comments
 (0)