swift
[SourceKit] Update requests to handle locations within generated buffers
#64456
Merged

[SourceKit] Update requests to handle locations within generated buffers #64456

bnbarham merged 1 commit into swiftlang:main from bnbarham:nested-cursor
bnbarham
bnbarham2 years ago

Update requests to handle being passed a separate key.primary_file which specifies the file to use for building the AST. key.sourcefile is then the file to find in SourceManager, which could be a generated buffer.

Resolves rdar://106863186.

bnbarham bnbarham requested a review from rintaro rintaro 2 years ago
bnbarham bnbarham requested a review from ahoppen ahoppen 2 years ago
bnbarham bnbarham requested a review from hamishknight hamishknight 2 years ago
bnbarham bnbarham force pushed from 441e1cae to fea46070 2 years ago
bnbarham bnbarham force pushed from fea46070 to 941db553 2 years ago
bnbarham
bnbarham2 years ago

@swift-ci please test

ahoppen
ahoppen commented on 2023-03-17
Conversation is marked as resolved
Show resolved
tools/SourceKit/include/SourceKit/Core/LangSupport.h
ahoppen2 years ago

I don’t think there’s comment anywhere that describes the difference between PrimaryFile and InputFile. Could you add one somewhere? I wouldn’t mind if you repeated it in many places as I would be wondering what the difference is whenever I read code any of these functions.

bnbarham2 years ago

I'll add a comment... somewhere 🤔

bnbarham2 years ago

I added it to the functions that get primary_file/sourcefile

ahoppen2 years ago

Thanks

Conversation is marked as resolved
Show resolved
tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp
22552310 std::string error;
22562311
2257 auto fileSystem = getFileSystem(vfsOptions, filename, error);
2312
auto fileSystem = getFileSystem(vfsOptions, InputFile, error);
ahoppen2 years ago

Why do you use InputFile here but PrimaryFile almost everywhere else? I’m not saying this is wrong, I just don’t understand what drove the decision for InputFile vs PrimaryFile yet.

bnbarham2 years ago

They should all be InputFile. I only see the one PrimaryFile in diagnostics. That one is a little confusing because diagnostics don't take an input file, only a primary file. Things are even more confusing because getFileSystem used to take a primaryFile and I've now changed what that actually means - we previously used "source file", "primary file", and "input file" interchangeably. I'll fix up all the callsites that currently have primaryFile= as their comment (since I renamed the arg).

InputFile == buffer we're doing the request on, could be a generated buffer name
PrimaryFile == file to build AST for
SourceFile == I'd prefer this isn't used, it can really mean either

bnbarham2 years ago

I think I've changed my mind here. It doesn't really make sense to be able to provide a VFS for a generated input buffer name. So I'll change this back to use primary file.

ahoppen2 years ago

OK, makes sense to me 👍🏽

Conversation is marked as resolved
Show resolved
tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp
ahoppen2 years ago

What do you think about naming all the StringRefs PrimaryFileName and InputFileName. That creates a clear distinction between filenames and the files themselves.

bnbarham2 years ago

Name is kind of weird to me since for a path on disk it implies the name rather than full path. I'd somewhat expect the contents itself to be called <whatever>FileContents. How strongly do you feel about this?

ahoppen2 years ago

Not too strongly. It’s mostly that I expect PrimaryFile to be of type SourceFile * while reading the body of the function without the signature and not a StringRef. InputFilePath would be an alternative name. But if you have strong feelings, feel free to keep it as-is.

bnbarham2 years ago

Path has similar issues, ie. it implies a path on disk when InputFile can actually just be the buffer name. These could be PrimaryFilePath and InputBufferName though, since the former is always a path and the latter is meant to be a buffer name/identifier, not a path/filename. Time for lots of renaming 😅

bnbarham2 years ago

I renamed them all to PrimaryFilePath and InputBufferName. Hopefully that's more clear.

Conversation is marked as resolved
Show resolved
tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp
11231121
1122 if (!Opts.PrimaryFile.empty()) {
1123 sourcekitd_request_dictionary_set_string(Req, KeyPrimaryFile,
1124
Opts.PrimaryFile.c_str());
ahoppen2 years ago

Did we previously set KeyPrimaryFile to an empty string if no primary file was passed?

bnbarham2 years ago

We didn't set it at all. KeyPrimaryFile is new and I only added it for refactorings (see the removal in this file).

Conversation is marked as resolved
Show resolved
tools/SourceKit/tools/sourcekitd/lib/Service/Requests.cpp
13791381
13801382 handleSemanticRequest(Req, Rec, [Req, Rec]() {
1381 auto SourceFile = getPrimaryFileForRequestOrEmitError(Req, Rec);
1383 Optional<StringRef> SourceFile =
1384
getSourceFileForRequestOrEmitError(Req, Rec);
ahoppen2 years ago

Since this is now returning the file name what do you think about renaming the function to getSourceFileNameForRequestOrEmitError?

bnbarham2 years ago

See my other comment. Though given the LSP test failures on Linux (which are quite confusing to me), I'm actually going to change this to getInputFile which will return key.sourcefile only if it is different from key.primary_file and an empty string otherwise.

bnbarham bnbarham force pushed from 941db553 to 2347629c 2 years ago
bnbarham bnbarham force pushed from 2347629c to 88d00237 2 years ago
bnbarham
bnbarham2 years ago

@swift-ci please test

bnbarham bnbarham force pushed from 88d00237 to 425371cb 2 years ago
bnbarham
bnbarham2 years ago

@swift-ci please test

bnbarham [SourceKit] Update requests to handle locations within generated buffers
b2b5b196
bnbarham bnbarham force pushed from 425371cb to b2b5b196 2 years ago
bnbarham
bnbarham2 years ago

@swift-ci please test

ahoppen
ahoppen approved these changes on 2023-03-24
bnbarham bnbarham merged 323745dc into main 2 years ago
bnbarham bnbarham deleted the nested-cursor branch 2 years ago

Login to write a write a comment.

Login via GitHub

Assignees
No one assigned
Labels
Milestone