timknapen / Arduino-With-XCode

Developing on Arduino with XCode instead of the Arduino IDE
33 stars 6 forks source link

Codesense not working all the time in XCode 3.2 #3

Open timknapen opened 13 years ago

timknapen commented 13 years ago

The Auto Suggestion feature of XCode3.2 doesn't work "sometimes"... If you add a class to ProjectFolder/src/ the auto completion works, but the exact same code for one of the standard library classes in Arduino.app doesn't trigger the auto completion correctly.

example:

ArduinoProgram.h

#ifndef ARDUINO_PROGRAM_H
#define ARDUINO_PROGRAM_H

#include "WProgram.h"
#include "Stepper.h"    // in Arduino.app
#include "TestThing.h"  // in Projectfolder/src/ 

class ArduinoProgram {
public:

    void setup();
    void loop();

    // variables
    TestThing thing1;
    TestThing* thingPointer1;

    Stepper stepper1;
    Stepper* stepperPointer1;

};

#endif

ArduinoProgram.cpp

#include "ArduinoProgram.h"

void ArduinoProgram::setup(){

    // These work
    thing1.doSomething(0);          // CodeSense suggested void doSomething(int variable)

    thingPointer1->doSomething(0);  // CodeSense suggested void doSomething(int variable)

    TestThing thing2;
    thing2.doSomething(0);          // CodeSense suggested void doSomething(int variable)

    TestThing* thingPointer2;       
    thingPointer2->doSomething(0);  // CodeSense suggested void doSomething(int variable)

    // These fail:
    stepper1.step(0);               // CodeSense says "No completions found"

    stepperPointer1->step(0);       // CodeSense says "No completions found"

    // These Work:
    Stepper stepper2;
    stepper2.step(0);               //CodeSense suggested void step(int number_of_steps)

    Stepper * stepperPointer2;
    stepperPointer2->step(0);       //CodeSense suggested void step(int number_of_steps)

}

void ArduinoProgram::loop(){
    //
}

TestThing.h

#ifndef TEST_THING
#define TEST_THING

#include "WProgram.h"

class TestThing{
public:
    void doSomething(int variable);

};

#endif

TestThing.cpp:

#include "TestThing.h"

void TestThing::doSomething(int variable){
    // do something
}
rei-vilo commented 12 years ago

Neither on Xcode 4.2 for release prettier output, better extracting variables from boards dated Jan 23, 2012

Xcode specialists, any idea?

timknapen commented 12 years ago

Just switched on the Lion machine, taking a look at it NOW. :-)

rei-vilo commented 12 years ago

Good luck ;-)

timknapen commented 12 years ago

Ok codesense is working consistently everywhere now in Xcode 4 check my "experimental" branch of the project.

The way to make sure that everything works in Code sense is this: In the project navigator click on your project > Targets > fake target > build phases > expand "Compile sources" press the "+" button at the bottom and in the list that pops up, just select all your .c, .cpp and .h files.

They are now happily code completing :-) yaay!

rei-vilo commented 12 years ago

Serial.print() is still in black :-(

timknapen commented 12 years ago

yeah I've noticed after uploading... will investigate soon, I feel we're getting closer and closer.

timknapen commented 12 years ago

investigated and fixed :-) fix depends on Arduino.app being in /Applications/ though... so it's not perfect...

rei-vilo commented 12 years ago

Release timknapen-Arduino-With-XCode-3dec20f does provide code sense for all libraries.

Great!

However, is there an easier way?

rei-vilo commented 12 years ago

In the project navigator click on your project > Targets > fake target > build phases > expand "Compile sources" press the "+" button at the bottom and in the list that pops up, just select all your .c, .cpp and .h files.

Instead of adding manually each and every files, couldn't we pass a list of those file.

To obtain a list of all the .c .cpp .h file, try this:

# Comments: 
#   := immediate assignment
#   ~ is accepted in makefile but requires translation with wildcard

# List of all h c cpp files within ARDUINO_DIR

ARDUINO_DIR := /Applications/Mpide.app/Contents/Resources/Java
EXCLUDE     := %xample %xamples %eference %rchive %ocumentation

DIRS   := $(filter-out $(EXCLUDE),$(shell find $(ARDUINO_DIR) -type d -print))
FILES1 := $(foreach file,$(DIRS),$(wildcard $(file)/*.h))
FILES2 := $(foreach file,$(DIRS),$(wildcard $(file)/*.c))
FILES3 := $(foreach file,$(DIRS),$(wildcard $(file)/*.cpp))
LIST   := $(FILES1) $(FILES2) $(FILES3)

all:
    @echo " \n"
    @echo "----DIRS"
    @echo $(DIRS)
    @echo " "
    @echo "----FILES1"
    @echo $(FILES1)
    @echo " "
    @echo "----FILES2"
    @echo $(FILES2)
    @echo " "
    @echo "----FILES3"
    @echo $(FILES3)
    @echo " "
    @echo "----LIST"
    @echo $(LIST)
    @echo " "
rei-vilo commented 12 years ago

I can't replicate the trick on a MPIDE based configuration.

So the tip seems to be trickier than expected!