Skip to content

Commit ae81833

Browse files
authored
Merge pull request #10 from touchlab/Xcode11
Xcode 11 changes
2 parents da38dd1 + 2819a48 commit ae81833

File tree

7 files changed

+514
-51
lines changed

7 files changed

+514
-51
lines changed

Kotlin.ideplugin/Contents/Resources/konan_lldb.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ def __none(iterable, f):
286286
return not any(f(x) for x in iterable)
287287
if __none(self._children, lambda x: x.name() == name):
288288
return -1
289-
# return (i for i,v in enumerate(self._children) if v.name() == name).__next__()
290-
return (i for i,v in enumerate(self._children) if v.name() == name).next()
289+
return next((i for i,v in enumerate(self._children) if v.name() == name))
291290

292291
def get_child_at_index(self, index):
293292
result = self._values[index]
@@ -391,4 +390,4 @@ def __lldb_init_module(debugger, _):
391390
')
392391
debugger.HandleCommand('type category enable Kotlin')
393392
debugger.HandleCommand('command script add -f {}.print_this_command print_this'.format(__name__))
394-
debugger.HandleCommand('command script add -f {}.clear_cache_command clear_kotlin_cache'.format(__name__))
393+
debugger.HandleCommand('command script add -f {}.clear_cache_command clear_kotlin_cache'.format(__name__))

Kotlin.xclangspec

100755100644
File mode changed.

README.md

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,55 @@ set breakpoints and includes llvm support to view data in the debug window.
99
> Touchlab is looking for Android-focused mobile engineers, experienced with Kotlin and
1010
> looking to get involved with Kotlin Multiplatorm in the near future. [More info here](https://on.touchlab.co/2P94J5q).
1111
12-
## Blog post and live demo
12+
# Xcode 11+
1313

14-
Check out the [blog post and sign up for the live video demo](https://medium.com/@kpgalligan/kotlin-xcode-plugin-64f52ff8dc2a) on Friday 4/26 (3pm EST).
14+
Xcode does not officially support custom language definitions, but they also don't explicitly block them. However,
15+
Xcode 11 introduced several breaking changes from earlier versions, and some resolutions are still outstanding.
1516

16-
## Installation
17+
## Xcode <= 10.x
1718

18-
### Watch Video
19+
For earlier versions, please see [xcode10 branch](https://github.com/touchlab/xcode-kotlin/tree/xcode10). Life moves on,
20+
and we'll only be supporting Xcode 11+.
1921

20-
[![Kotlin Xcode Setup](https://img.youtube.com/vi/CqzSyWI_esY/0.jpg)](https://www.youtube.com/watch?v=CqzSyWI_esY)
22+
## Installation
2123

22-
### Setup script
24+
There are 2 parts to Kotlin support: 1) debugging support and 2) language color and style formatting.
2325

24-
Run the following command in your terminal:
26+
### Step 1: Debugging Support
27+
28+
You need to tell Xcode that `*.kt` files are source files, and run an lldb formatter script when debugging starts.
29+
Advanced users may want to do this manually, but if you have Xcode installed in the default place, you can run the
30+
setup script.
2531

2632
```
2733
./setup.sh
2834
```
2935

30-
### Manual installation
36+
### Step 2: Formatting Support
37+
38+
In Xcode 11, you need to move some files into a protected area. Some users may not want to do this, and may possibly
39+
not have permissions to do this. You'll need to run the script with sufficient permissions, which generally means
40+
`sudo`.
3141

32-
Please note that if you are running Xcode 8 the `Plug-ins` and `Specifications` directories might not exist.
42+
*You can still debug Kotlin without formatting support, just FYI. This step is not required.*
3343

34-
- Copy the `Kotlin.ideplugin` directory to `~/Library/Developer/Xcode/Plug-ins/`:
44+
```
45+
sudo ./colorsetup.sh
46+
```
47+
48+
### Special Note
3549

36-
```
37-
cp -r Kotlin.ideplugin ~/Library/Developer/Xcode/Plug-ins/
38-
```
39-
- Copy the `Kotlin.xclangspec` file to `~/Library/Developer/Xcode/Specifications`:
50+
All of that magic was sorted out by [Ellen Shapiro](https://github.com/designatednerd), who undrestands all of this
51+
far better than I ever will.
52+
53+
[Tracking Issue Here](https://github.com/apollographql/xcode-graphql/issues/23)
4054

41-
```
42-
cp Kotlin.xclangspec ~/Library/Developer/Xcode/Specifications/
43-
```
55+
### Setup script
4456

45-
lldb formatting support is provided by konan_lldb.py. The setup script will add
46-
the path to `~/.lldbinit`. You can manually load this script at the lldb prompt
47-
with
57+
Run the following command in your terminal:
4858

4959
```
50-
command script import ~/Library/Developer/Xcode/Plug-ins/Kotlin.ideplugin/Contents/Resources/konan_lldb.py
60+
./setup.sh
5161
```
5262

5363
### Usage
@@ -75,21 +85,7 @@ support an interactive debugger.
7585
The current version of the plugin will still allow you to add breakpoints and run the debugger, but source code highlighting is not yet functional. When Xcode 11 releases
7686
we'll dig back into the situation.
7787

78-
## Coming Soon
79-
80-
### LLDB Formatter
81-
82-
The plugin itself relies on the lldb python formatter which was mostly adapted from the lldb formatter that comes with Kotlin Native. That script was really written for command line use. In an interactive context (like this plugin) the performance isn't great. Most of our changes are around optimizations. However, there are ongoing changes both to the underlying script and (possibly) to the memory layout of Kotlin Native itself at runtime.
83-
84-
The script in this plugin could use a refresh with a more recent base version from Kotlin Native, and if possible, refactor the optimizations to be as close to "stock" as possible, to make future updates easier.
85-
86-
The formatter also takes a very basic approach to data formatting. Lists are capped at 20 entries to avoid super long refreshes. Maps show their underlying data structures, but could get custom formatting (for example). There is a lot that could be done.
87-
88-
We currently can't get some things like class name. This could be enabled with moderate additions to Kotlin Native debug facilities.
89-
90-
### Debug aligning
91-
92-
The breakpoints and runtime *usually* line up, but they can get weird. This is especially true around things like lambdas. This *may* be related to what the llvm compiler is writing, or it may simply be an artifact of how Xcode is setting breakpoints. We'll need reports and repros of code that confuses the debugger to see if that can be improved.
88+
## Possible Future Stuff
9389

9490
### Color File
9591

@@ -99,6 +95,16 @@ The color definition is basically Java's with minor additions. This could be bet
9995

10096
It's a bash script, which works, but does not take into account non-standard install directories and various other possible config options. This could be improved.
10197

98+
### From Swift
99+
100+
You can see variables when you're debugging Kotlin, but when you're in a swift file that has a class that came from Kotlin
101+
you can't see much. It would be great to be able to improve that.
102+
103+
### Better Debug Alignment
104+
105+
This happens in the Kotlin compiler, so it's a little deeper, but the breakpoints don't always track with the source
106+
when there are more complex structures (lambdas, etc). This should improve over time.
107+
102108
## Xcode Updates
103109

104110
Every time Xcode is updated we need the UUID. It needs to be added to `Kotlin.ideplugin/Contents/Info.plist`. To find the
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>commentSyntaxes</key>
6+
<array>
7+
<dict>
8+
<key>prefix</key>
9+
<string>/*</string>
10+
<key>suffix</key>
11+
<string>*/</string>
12+
</dict>
13+
<dict>
14+
<key>prefix</key>
15+
<string>//</string>
16+
</dict>
17+
</array>
18+
<key>conformsToLanguageIdentifiers</key>
19+
<array>
20+
<string>Xcode.SourceCodeLanguage.Generic</string>
21+
</array>
22+
<key>documentationSyntaxes</key>
23+
<array>
24+
<dict>
25+
<key>prefix</key>
26+
<string>/**</string>
27+
<key>suffix</key>
28+
<string>*/</string>
29+
</dict>
30+
<dict>
31+
<key>prefix</key>
32+
<string>/*!</string>
33+
<key>suffix</key>
34+
<string>*/</string>
35+
</dict>
36+
<dict>
37+
<key>prefix</key>
38+
<string>///</string>
39+
</dict>
40+
<dict>
41+
<key>prefix</key>
42+
<string>//!</string>
43+
</dict>
44+
</array>
45+
<key>fileDataTypeIdentifiers</key>
46+
<array>
47+
<string>org.kotlinlang.kotlin-source</string>
48+
</array>
49+
<key>identifier</key>
50+
<string>Xcode.SourceCodeLanguage.Kotlin</string>
51+
<key>isHidden</key>
52+
<false/>
53+
<key>languageName</key>
54+
<string>Kotlin</string>
55+
<key>languageSpecification</key>
56+
<string>xcode.lang.kotlin</string>
57+
<key>supportsIndentation</key>
58+
<true/>
59+
<key>allowWhitespaceTrimming</key>
60+
<true/>
61+
<key>requiresHardTabs</key>
62+
<false/>
63+
</dict>
64+
</plist>

colorsetup.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
###################
4+
# LANGUAGE SPEC
5+
###################
6+
7+
spec_dir=/Applications/Xcode.app/Contents/SharedFrameworks/SourceModel.framework/Versions/A/Resources/LanguageSpecifications
8+
9+
cp Kotlin.xclangspec $spec_dir
10+
11+
meta_dir=/Applications/Xcode.app/Contents/SharedFrameworks/SourceModel.framework/Versions/A/Resources/LanguageMetadata
12+
13+
cp Xcode.SourceCodeLanguage.Kotlin.plist $meta_dir

0 commit comments

Comments
 (0)