Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any idea why source kit is throwing this error - ASTInvocation problem ? #697

Open
pkasson opened this issue Apr 29, 2021 · 12 comments
Open

Comments

@pkasson
Copy link

pkasson commented Apr 29, 2021

sourcekit: [1:getCursorInfo: 0.0000] failed to create an ASTInvocation: '/home/ubuntu/dev/swift/SourceKittenUtil/temp/AnishaApril26/AnishaApril26-master/AnishaProduct/ContentView.swift' is not part of the input files

Have seen this on a number of files, and the files exist and appear to be valid structs, or class files.

@johnfairh
Copy link
Collaborator

Just what the message says really: it means Swift thinks that the source file you are querying (key.sourcefile) does not appear in the list of files passed to the compiler for compilation (key.compilerargs).

If you think your keys are consistent then you should take a full example to bugs.swift.org.

@pkasson
Copy link
Author

pkasson commented Apr 29, 2021

So, this is not something being compiled, but parsed by source kit - it feels like something wrong with the source, something it does not understand, like SwiftUI or something new it cant comprehend.

@pkasson
Copy link
Author

pkasson commented Apr 29, 2021

How can you catch this error during this parsing process

@johnfairh
Copy link
Collaborator

No, nothing at all to do with "the parsing process", it's about the keys in your sourcekit request per my previous comment.

@pkasson
Copy link
Author

pkasson commented Apr 29, 2021

So, when source kit starts to analyze the source in a project, it encounters a file it did not get passed for compilation.

Not sure I fully understand how source kit is doing its thing, but if it is acting on files in a project, using SourceKitten, is it compiling the source in order to obtain the key and structure data ?

@johnfairh
Copy link
Collaborator

The compiler args are supplied by the user or taken from the build tool CLI/record.

If you are not making sourcekit requests directly, can you explain exactly which sourcekitten interface you are using when you see this problem?

If you are running sourcekitten doc or the API equivalent against an Xcode project/SPM package then we'll need to see an example of a project with the problem.

@pkasson
Copy link
Author

pkasson commented Apr 29, 2021

 /*
  * get stucture for a source file
  */
 func getStructure(filePath :String) -> Structure?
 {
  var structure : Structure
  
  do                                                                
  {
   structure = try Structure(file: File(path: filePath)!)
   
   return structure
  }
  catch let error
  {
   logger.logError(message: "getStructure - error:  \(error.localizedDescription)")
  }
  
  return nil
 }

@johnfairh
Copy link
Collaborator

None of that sends a cursorInfo request. If you have a source file that causes the cursorInfo error from the OP when you run that Structure query (sends source.request.editor.open) then that should go to bugs.swift.org.

@pkasson
Copy link
Author

pkasson commented May 19, 2021

Maybe I dont understand what SourceKitten is doing - when it does interact with SourceKit, is it in fact compiling things, and that this is necessary to obtain structure and other artifacts ?

If not, I see that in SourceKit itself, it is indeed getting this error here:

Utils.cpp - gets initCompilerInvocation invoked, which in turn calls resolveSymbolicLinksInInputs

resolveSymbolicLinksInInputs is the method throwing that error: OS << "'" << PrimaryFile << "' is not part of the input files";

So ... if SourceKitten is calling SourceKit to do its thing, that sounds like a bug in SourceKitten ?

@johnfairh
Copy link
Collaborator

SourceKit runs various phases of the compiler to implement the requests you send through SourceKitten.

Your OP suggests SourceKit was sent a CursorInfo request.

Your code could be sending this directly, or using SourceKitten's docs generation APIs (SwiftDocs, Module.docs).
If you are sending a Request directly, or using SwiftDocs directly, or using Module.init(name:compilerArguments:), then the compiler arguments are under your control.

If you are using SourceKitten's end-to-end docs generation via a different Module initializer then SourceKitten is responsible for figuring out the compiler arguments via a build tool.

@pkasson
Copy link
Author

pkasson commented May 20, 2021

I took out the call to get documentation .. and I have a lot fewer errors as shown earlier.
Here is my call, using kitten:

 /*
  * get comments / docs for a source file
  */
 func getDoc(filePath :String) -> [String: SourceKitRepresentable]
 {
  var args = [String]()
  args.append("single-file")
  
  let docs = SwiftDocs(file: File(path: filePath)!, arguments: args)
  
  return docs!.docsDictionary
 }

This used to work without issue (not all issues as described earlier), but now, some, not all, shoot out tons of error messages about ASTInvocation. Is this call not correct ?

@johnfairh
Copy link
Collaborator

The arguments here should be the Swift compiler arguments required to compile the module/part-module that contains filePath. The sourcekit docs describe this:

Array of zero or more strings for the compiler arguments, e.g ["-sdk", "/path/to/sdk"]. If key.sourcefile is provided, these must include the path to that file.

SourceKitten passes them through to SourceKit without touching them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants