Skip to content
This repository was archived by the owner on Apr 1, 2020. It is now read-only.

Fix updating detailed completion for overloaded methods #2633

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions browser/src/Services/Completion/CompletionStore.ts
Original file line number Diff line number Diff line change
@@ -134,6 +134,16 @@ export const completionResultsReducer: Reducer<ICompletionResults> = (
return {
...state,
completions: state.completions.map(completion => {
// Prefer `detail` field if available, to avoid splatting e.g. methods with
// the same name but different signature.
if (completion.detail && action.completionItemWithDetails.detail) {
if (completion.detail === action.completionItemWithDetails.detail) {
return action.completionItemWithDetails
} else {
return completion
}
}

if (completion.label === action.completionItemWithDetails.label) {
return action.completionItemWithDetails
} else {
66 changes: 66 additions & 0 deletions browser/test/Services/Completion/CompletionStoreTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import * as assert from "assert"
import * as _ from "lodash"

import { DefaultCompletionResults } from "./../../../src/Services/Completion/CompletionState"
import { completionResultsReducer } from "./../../../src/Services/Completion/CompletionStore"

describe("completionResultsReducer", () => {
let oldState: any

beforeEach(() => {
oldState = _.cloneDeep(DefaultCompletionResults)
})

describe("GET_COMPLETION_ITEM_DETAILS_RESULT", () => {
beforeEach(() => {
oldState.completions = [
{ label: "other" },
{ label: "matchme", detail: "matchme(signature)" },
{ label: "matchme", detail: "other(signature)" },
{ label: "matchme" },
]
})

it("updates relevant items with detailed version by label field", () => {
const completionItemWithDetails = {
label: "matchme",
}

const newState = completionResultsReducer(oldState, {
type: "GET_COMPLETION_ITEM_DETAILS_RESULT",
completionItemWithDetails,
})

assert.deepStrictEqual(newState, {
...oldState,
completions: [
{ label: "other" },
completionItemWithDetails,
completionItemWithDetails,
completionItemWithDetails,
],
})
})

it("updates relevant items with detailed version by detail field", () => {
const completionItemWithDetails = {
label: "matchme",
detail: "matchme(signature)",
}
const newState = completionResultsReducer(oldState, {
type: "GET_COMPLETION_ITEM_DETAILS_RESULT",
completionItemWithDetails,
})

assert.deepStrictEqual(newState, {
...oldState,
completions: [
{ label: "other" },
completionItemWithDetails,
{ label: "matchme", detail: "other(signature)" },
completionItemWithDetails,
],
})
})
})
})