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

feat(typescript): upgrade to typescript 2.6.2 #430

Merged
merged 1 commit into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"rxjs": "^5.5.0",
"semaphore-async-await": "^1.5.1",
"string-similarity": "^1.1.0",
"typescript": "2.4.2",
"typescript": "2.6.2",
"vscode-jsonrpc": "^3.3.1",
"vscode-languageserver": "^3.1.0",
"vscode-languageserver-types": "^3.0.3"
Expand Down
12 changes: 6 additions & 6 deletions src/test/typescript-service-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2297,11 +2297,11 @@ export function describeTypeScriptService(
uri: 'git://github.com/Microsoft/TypeScript?v' + ts.version + '#lib/lib.dom.d.ts',
range: {
start: {
line: 8259,
line: 8428,
character: 10,
},
end: {
line: 8259,
line: 8428,
character: 14,
},
},
Expand All @@ -2310,11 +2310,11 @@ export function describeTypeScriptService(
uri: 'git://github.com/Microsoft/TypeScript?v' + ts.version + '#lib/lib.dom.d.ts',
range: {
start: {
line: 8311,
line: 8480,
character: 12,
},
end: {
line: 8311,
line: 8480,
character: 16,
},
},
Expand Down Expand Up @@ -3028,7 +3028,7 @@ export function describeTypeScriptService(
},
position: {
line: 1,
character: 13,
character: 12,
},
})
.reduce<Operation, CompletionList>(applyReducer, null as any)
Expand All @@ -3039,7 +3039,7 @@ export function describeTypeScriptService(
{
data: {
entryName: 'bar',
offset: 51,
offset: 50,
uri: rootUri + 'uses-reference.ts',
},
label: 'bar',
Expand Down
47 changes: 25 additions & 22 deletions src/typescript-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,25 @@ export interface Settings extends PluginSettings {
/**
* Maps string-based CompletionEntry::kind to enum-based CompletionItemKind
*/
const completionKinds: { [name: string]: CompletionItemKind } = {
class: CompletionItemKind.Class,
constructor: CompletionItemKind.Constructor,
enum: CompletionItemKind.Enum,
field: CompletionItemKind.Field,
file: CompletionItemKind.File,
function: CompletionItemKind.Function,
interface: CompletionItemKind.Interface,
keyword: CompletionItemKind.Keyword,
method: CompletionItemKind.Method,
module: CompletionItemKind.Module,
property: CompletionItemKind.Property,
reference: CompletionItemKind.Reference,
snippet: CompletionItemKind.Snippet,
text: CompletionItemKind.Text,
unit: CompletionItemKind.Unit,
value: CompletionItemKind.Value,
variable: CompletionItemKind.Variable,
}
const completionKinds = new Map<string, CompletionItemKind>([
[`class`, CompletionItemKind.Class],
[`constructor`, CompletionItemKind.Constructor],
[`enum`, CompletionItemKind.Enum],
[`field`, CompletionItemKind.Field],
[`file`, CompletionItemKind.File],
[`function`, CompletionItemKind.Function],
[`interface`, CompletionItemKind.Interface],
[`keyword`, CompletionItemKind.Keyword],
[`method`, CompletionItemKind.Method],
[`module`, CompletionItemKind.Module],
[`property`, CompletionItemKind.Property],
[`reference`, CompletionItemKind.Reference],
[`snippet`, CompletionItemKind.Snippet],
[`text`, CompletionItemKind.Text],
[`unit`, CompletionItemKind.Unit],
[`value`, CompletionItemKind.Value],
[`variable`, CompletionItemKind.Variable],
])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was the reason to make this a Map, given it never changes?

Copy link
Contributor Author

@daviwil daviwil Feb 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using constructor as an object property name caused type system problems with CompletionItemKind, somehow it inferred that Function was a part of the union of numbers that CompletionItemKind is aliased to. I couldn't find another way to escape the known keyword of constructor so using a map seemed to be the next best option. Happy to change it back if you know of a better way!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that makes total sense!


/**
* Handles incoming requests and return responses. There is a one-to-one-to-one
Expand Down Expand Up @@ -1182,7 +1182,7 @@ export class TypeScriptService {
params.position.line,
params.position.character
)
const completions = configuration.getService().getCompletionsAtPosition(fileName, offset)
const completions = configuration.getService().getCompletionsAtPosition(fileName, offset, undefined)

if (!completions) {
return []
Expand All @@ -1192,7 +1192,7 @@ export class TypeScriptService {
.map(entry => {
const item: CompletionItem = { label: entry.name }

const kind = completionKinds[entry.kind]
const kind = completionKinds.get(entry.kind)
if (kind) {
item.kind = kind
}
Expand Down Expand Up @@ -1233,7 +1233,10 @@ export class TypeScriptService {
const configuration = this.projectManager.getConfiguration(fileName)
configuration.ensureBasicFiles(span)

const details = configuration.getService().getCompletionEntryDetails(fileName, offset, entryName)
const details = configuration
.getService()
.getCompletionEntryDetails(fileName, offset, entryName, undefined, undefined)

if (details) {
item.documentation = ts.displayPartsToString(details.documentation)
item.detail = ts.displayPartsToString(details.displayParts)
Expand Down