Skip to content

Problems with ChatVariablesService#attachContext #229712

Open
@jrieken

Description

There is couple of issues and code smell with attachContext

async attachContext(name: string, value: string | URI | Location, location: ChatAgentLocation) {
if (location !== ChatAgentLocation.Panel) {
return;
}
const widget = this.chatWidgetService.lastFocusedWidget ?? await showChatView(this.viewsService);
if (!widget || !widget.viewModel) {
return;
}
const key = name.toLowerCase();
if (key === 'file' && typeof value !== 'string') {
const uri = URI.isUri(value) ? value : value.uri;
const range = 'range' in value ? value.range : undefined;
widget.getContrib<ChatContextAttachments>(ChatContextAttachments.ID)?.setContext(false, { value, id: uri.toString() + (range?.toString() ?? ''), name: basename(uri.path), isFile: true, isDynamic: true });
return;
}
const resolved = this._resolver.get(key);
if (!resolved) {
return;
}
widget.getContrib<ChatContextAttachments>(ChatContextAttachments.ID)?.setContext(false, { ...resolved.data, value });
}

  • it checks for the ChatLocation - something that we have gotten past since a while
  • it uses the last focused widget which can very well be of another ChatLocation
  • it opens the chat panel (showChatView) if it finds no other widget - this is really awkward and bad

IMO instead the method should just be called with a target widget

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

chatdebtCode quality issuesimportantIssue identified as high-priority

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions