Issue with Code Autocompletion/Syntax Highlighting in Xcode 4.X

Issue with code autocompletion / syntax highlighting in Xcode 4.x

I suffered for a long time with a project that kept losing auto-completion and syntax highlighting. Deleteing the Derived Data folder and restarting Xcode would fix it temporarily, and eventually that almost became muscle memory. My problem seemed to be exacerbated by using a workspace that contained multiple projects, many of which were dependant on each other. It turns out the problem was with the clang indexer. The project would compile cleanly, but looking at the output from the indexer it was littered with errors. Fixing ALL these resolved my problems.

BEFORE DOING ANYTHING: make sure ALL the targets in ALL the projects in your Workspace compile cleanly. That's without ANY warnings. This was a big failure on my part - I had old targets that just didn't compile cleanly. Some of these were unused and could be deleted, others were non-ARC that used modules in targets that had been converted to ARC (converted those targets too), and some just needed the code fixing.

Once you've resolved ALL those problems, the first thing we need to know is where the indexer is failing, by doing a complete index of your project.

  • First, Make sure Xcode is closed, then turn up the indexer warning
    message level by entering in the Terminal:

     defaults write com.apple.dt.Xcode IDEIndexingClangInvocationLogLevel 3
  • Then find the Derived Data folder for your project/workspace (probably ~/Library/Developer/Xcode/DerivedData/your project name-some gibberish), and delete it (but keep the Derived Data folder open because you'll probably have to go back and do this a few times.

  • Next, open the Console app and click Clear Display, and set the filter to "IDE" to only show the messages we're interested in.

  • Finally, open Xcode and the project/workspace that's causing your problems, and you'll see the console start to fill up with messages.

  • To look for errors, change the Console filter to "error:" - our aim is to reduce these to zero.

  • The majority of errors I found were missing header files. Xcode itself seems to be smarter than the indexer. It seems to be able to find and include header files from other projects that the indexer can't.

  • So, anywhere you see "fatal error: 'somefile.h' file not found", make sure you add the path of that file to the User Header Search Paths in the target's build settings. The best way I've found to do this is to double click on the field to get the popup, and drag the folder from the finder into it. This adds a new entry, but assuming it's in the same workspace, it adds a relative file path (this is important in case you move your workspace folder in the future). If you've got multiple targets for the same project, you can set the search path at the project rather than target level, and set the target search paths to $(inherited).

  • You might have similar problems with Libraries or Frameworks - again, update the appropriate search path.

  • Once your fixed some errors, close Xcode, clear the console, delete the project's Derived Data, open Xcode and let it index again.

  • Repeat until all your errors are gone.

Once you're in this good place, code autocomplete and syntax highlighting should work like a charm :)

Xcode 8 syntax highlighting doesn't work

Fixed. Problem was related to the presence of target in project which is not compiled. So if you have targets e.g. A, B, C and C is not compiled this cause problems with syntax highlighting.

Code highlighting and autocomplete gone in Xcode

Ok, I figured it out. I had Core-Plot in the framework area of my project, and Xcode was looking to resolve Core-Plot as a framework even though it was just a binary and the associated headers. So I moved Core-Plot into a folder with my other classes, removed the old Core-Plot path from the library search paths and also blew away the header search paths and now my autocomplete and code highlighting is back!! I think this is a bug in Xcode...

Xcode 8.3 autocomplete and syntax highlighting not working

Turned out the issue was caused by my own action (mistake).

Long ago, when I had my first brief interaction with Xcode, I deliberately tried to disable its indexing, because it took too long on my Mac (which was not upgraded by that time). So I did that by typing this in the Terminal:

defaults write com.apple.dt.XCode IDEIndexDisable 1

And there it was. I totally forgot about this until I had to touch Xcode again recently, and was driven mad by the autocomplete and syntax highlighting "not working". There's no Xcode fault whatsoever. All I needed to do to make it work is enable indexing again, by typing this in the Terminal:

defaults delete com.apple.dt.Xcode IDEIndexDisable

I obviously created my own trouble, but hopefully this information will be helpful to someone else.

Thank everyone for your help.

Problems with Xcode Syntax Highlighting

Xcode is often glitchy for me in similar ways. Restarting xcode often clears up the issue. Also, sometimes a missing semi-colon or curly brace will keep codeSense and highlighting from working as you want it to. Try Opt-B (build) to see if you have any errors that could be causing this.

Problems with Xcode Syntax Highlighting

Xcode is often glitchy for me in similar ways. Restarting xcode often clears up the issue. Also, sometimes a missing semi-colon or curly brace will keep codeSense and highlighting from working as you want it to. Try Opt-B (build) to see if you have any errors that could be causing this.

Xcode's code sense and syntax coloring only work for some files in the project

Go to your organizer and in the projects tab find your project and click "Delete Derived Data" this forces XCode to reindex everything and does not hurt anything. It usually does the trick for me although sometimes XCode is just troublesome.

What's wrong with the syntax highlighter and autocompletion in Xcode using Swift

In this case it had something to do with CocoaPods. It was copying .h files into the build directory and SourceKit was getting confused.

I added this script to my project, and SourceKit stopped freaking out a bit, but it is still ridiculously slow.

function removeHeaders() {  
find $BUILD_ROOT/Debug-iphonesimulator/ -name '*.h' -exec rm -f {} \;
}
removeHeaders

Ref. Xcode Swift Syntax Highlighting and Code Completion Completely Broken

Note: Unfortunately this solution breaks debugging console and archiving. So remove the script if it is needed.



Related Topics



Leave a reply



Submit