Skip to content

Objective-C: Different behavior for .m and .h files #969

Open
@Allless

Description

@Allless

Context

Setting up autocompletion for Objective-C.
Filesystem:

.ccls
clang
-I/usr/GNUstep/Local/Library/Headers
-L/usr/GNUstep/Local/Library/Libraries
-lgnustep-base -lobjc
-fobjc-runtime=gnustep-2.0
src/main.m
#import <Foundation/Foundation.h>
#import "MyClass2.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // Create an instance of MyClass
        MyClass *myObject = [[MyClass alloc] init];
        
        // Call the sayHello method
        [myObject sayHello];
    }
    return 0;
}
src/MyClass.m
#import <Foundation/Foundation.h>

@interface MyClass : NSObject

- (void)sayHello;

@end

@implementation MyClass

- (void)sayHello {
    NSLog(@"Hello, World!");
}

@end
src/MyClass2.h
#import <Foundation/Foundation.h>

@interface MyClass : NSObject

- (void)sayHello;

@end

@implementation MyClass

- (void)sayHello {
    NSLog(@"Hello, World!");
}

@end

Observed behavior

  • The MyClass.m and MyClass2.h have the same content, and there are no custom arguments specified for the .m and .h files, but they get different error highlighting.
    • Specifically, the @interface syntax is highlighted as invalid in .h files, even though, the Foundation header is imported and recognized (you can use a go-to definition feature that will respond with the actual path).

image

  expected identifier or '('ccls(4)
  • Code can be compiled using the command from .ccls without errors, which means syntax is valid considering the project setup.

Expected behavior

  • Shouldn't be getting error highlighting in diagnostics if the project can be built successfully with the provided command
  • The language server should treat the .h and .m files in the same way for an Objective-C environment.

Steps to reproduce

  1. Use the file structure described in the "Observer behavior section"
  2. Initialize the language server, and send a didOpen notification for the .h file
  3. See that error diagnostics are being published
  4. Send a didOpen notification for the .m file with the same content
  5. See that no error diagnostics are published

  1. To make sure that the syntax is valid considering the project setup, compile the code using the following command, which is identical to the one in.ccls
clang -I/usr/GNUstep/Local/Library/Headers \
      -L/usr/GNUstep/Local/Library/Libraries \
      -lgnustep-base -lobjc \
      -fobjc-runtime=gnustep-2.0 \
      ./src/main.m  -o MyClassTest
  1. Run the MyClassTest executable. See that it is successful

System information

  • ccls version: 0.20190823.6-1~ubuntu1.20.04.1 (result of ccls --version)
  • clang version: 10.0.0-4ubuntu1
  • OS: Ubuntu 20
  • Editor: Monaco (can be any)
  • Language client (and version): Monaco-langaugeClient 0.18.1 (can be any)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions