Skip to content

Commit be9171a

Browse files
committed
Fix bug and marketplace publishing
1 parent 0fbc02b commit be9171a

File tree

11 files changed

+119
-93
lines changed

11 files changed

+119
-93
lines changed

CONTRIBUTING.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Contributing
2+
3+
All contributions are welcome. For instance bug fixes, increased test coverage and new features.
4+
5+
6+
## Pull Requests
7+
8+
* Open pull requests to the dev branch, not master.
9+
* Run the unit tests to ensure no existing functionality has been affected.
10+
* If applicable, write new unit tests to test your changes.
11+
* If applicable, update [README.md](https://github.com/njqdev/vscode-python-typehint/blob/master/README.md) to reflect your changes.
12+
13+
14+
## Contributor License Agreement
15+
16+
All contributions are subject to the following DCO.
17+
18+
```
19+
Developer Certificate of Origin
20+
Version 1.1
21+
22+
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
23+
1 Letterman Drive
24+
Suite D4700
25+
San Francisco, CA, 94129
26+
27+
Everyone is permitted to copy and distribute verbatim copies of this
28+
license document, but changing it is not allowed.
29+
30+
31+
Developer's Certificate of Origin 1.1
32+
33+
By making a contribution to this project, I certify that:
34+
35+
(a) The contribution was created in whole or in part by me and I
36+
have the right to submit it under the open source license
37+
indicated in the file; or
38+
39+
(b) The contribution is based upon previous work that, to the best
40+
of my knowledge, is covered under an appropriate open source
41+
license and I have the right under that license to submit that
42+
work with modifications, whether created in whole or in part
43+
by me, under the same open source license (unless I am
44+
permitted to submit under a different license), as indicated
45+
in the file; or
46+
47+
(c) The contribution was provided directly to me by some other
48+
person who certified (a), (b) or (c) and I have not modified
49+
it.
50+
51+
(d) I understand and agree that this project and the contribution
52+
are public and that a record of the contribution (including all
53+
personal information I submit with it, including my sign-off) is
54+
maintained indefinitely and may be redistributed consistent with
55+
this project or the open source license(s) involved.
56+
```

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 nj-q
3+
Copyright (c) 2020 njqdev
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
Provides type hint auto-completion for Python, with completion items for built-in types, classes and the typing module.
44

5-
![](demo.gif)
5+
6+
![](static/demo.gif)
67

78
## Features
89

@@ -20,7 +21,7 @@ Provides type hint auto-completion for Python, with completion items for built-i
2021

2122
## Installation
2223

23-
The extension can be installed manually with this [VSIX file](https://github.com/nj-q/vscode-python-typehint/releases/tag/v1.0.0).
24+
The extension can found on the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=njqdev.vscode-python-typehint).
2425

2526
## Known Issues
2627

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"name": "vscode-python-typehint",
33
"displayName": "Python Type Hint",
44
"version": "1.0.0",
5-
"publisher": "nj-q",
5+
"publisher": "njqdev",
66
"description": "Type hint completion for Python.",
7-
"icon": "images/icon.png",
7+
"icon": "static/icon.png",
88
"repository": {
99
"type": "git",
10-
"url": "https://github.com/nj-q/vscode-python-typehint"
10+
"url": "https://github.com/njqdev/vscode-python-typehint"
1111
},
1212
"license": "MIT",
1313
"categories": [
@@ -17,8 +17,8 @@
1717
"Python",
1818
"typehint",
1919
"completion",
20-
"type",
21-
"hint"
20+
"autocompletion",
21+
"parameter"
2222
],
2323
"engines": {
2424
"vscode": "^1.43.0"

src/completionProvider.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,24 @@ import {
1212
} from "vscode";
1313
import { TypeHintProvider } from "./typeHintProvider";
1414
import { paramHintTrigger, returnHintTrigger, PythonType, anyClassOrFunctionName } from "./python";
15-
import { TypeHint, labelFor } from "./typeHint";
1615
import { TypeHintSettings } from "./settings";
1716

1817

1918
abstract class CompletionProvider {
2019

2120
protected pushTypesToItems(typeNames: PythonType[], completionItems: CompletionItem[]) {
2221
for (const typeName of typeNames) {
23-
const item = new CompletionItem(labelFor(typeName), CompletionItemKind.TypeParameter);
22+
const item = new CompletionItem(this.labelFor(typeName), CompletionItemKind.TypeParameter);
2423

2524
// Add 999 to ensure they're sorted to the bottom of the CompletionList.
2625
item.sortText = `999${typeName}`;
2726
completionItems.push(item);
2827
}
2928
}
29+
30+
protected labelFor(typeName: string): string {
31+
return " " + typeName;
32+
}
3033
}
3134

3235
/**
@@ -53,7 +56,7 @@ export class ParamHintCompletionProvider extends CompletionProvider implements C
5356
const precedingText = line.text.substring(0, pos.character - 1).trim();
5457

5558
if (this.shouldProvideItems(precedingText, pos, doc)) {
56-
const param: string = this.findParam(precedingText, pos);
59+
const param: string = this.findParam(precedingText);
5760
const provider = new TypeHintProvider(doc, this.settings);
5861

5962
if (param.length > 0) {
@@ -73,10 +76,9 @@ export class ParamHintCompletionProvider extends CompletionProvider implements C
7376
* Finds the parameter which is about to be type hinted.
7477
*
7578
* @param precedingText Text preceding the active position.
76-
* @param pos The active position.
7779
* @returns The parameter.
7880
*/
79-
private findParam(precedingText: string, pos: Position): string {
81+
private findParam(precedingText: string): string {
8082
let param = "";
8183

8284
let i = precedingText.length - 1;
@@ -89,21 +91,17 @@ export class ParamHintCompletionProvider extends CompletionProvider implements C
8991
return param.trim();
9092
}
9193

92-
private pushEstimationsToItems(typeHints: TypeHint[], items: CompletionItem[]) {
94+
private pushEstimationsToItems(typeHints: string[], items: CompletionItem[]) {
9395

9496
if (typeHints.length > 0) {
95-
let typeHint = typeHints[0].label;
96-
let item = new CompletionItem(typeHint, CompletionItemKind.TypeParameter);
97-
item.sortText = `0${typeHint}`;
97+
let item = new CompletionItem(this.labelFor(typeHints[0]), CompletionItemKind.TypeParameter);
98+
item.sortText = `0${typeHints[0]}`;
9899
item.preselect = true;
99-
item.insertText = typeHints[0].insertText;
100100
items.push(item);
101101

102102
for (let i = 1; i < typeHints.length; i++) {
103-
typeHint = typeHints[i].label;
104-
item = new CompletionItem(typeHint, CompletionItemKind.TypeParameter);
105-
item.sortText = `${i}${typeHint}`;
106-
item.insertText = typeHints[i].insertText;
103+
item = new CompletionItem(this.labelFor(typeHints[i]), CompletionItemKind.TypeParameter);
104+
item.sortText = `${i}${typeHints[i]}`;
107105
items.push(item);
108106
}
109107
}

src/typeHint.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/typeHintProvider.ts

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { PythonType as PythonType, DataTypeContainer, getDataTypeContainer } fro
33
import { TypeSearch, VariableSearchResult } from "./typeSearch";
44
import { TypingHintProvider } from "./typingHintProvider";
55
import { WorkspaceSearcher } from "./workspaceSearcher";
6-
import { TypeHint, labelFor } from "./typeHint";
76
import { TypeHintSettings } from "./settings";
87

98
/**
@@ -21,7 +20,7 @@ export class TypeHintProvider {
2120
PythonType.Float
2221
];
2322
private typeContainer: DataTypeContainer = getDataTypeContainer();
24-
private typesIncludedInResult: { [key: string]: string } = {};
23+
private typeNamesIncludedInResult: string[] = [];
2524
private doc: TextDocument;
2625
private settings: TypeHintSettings;
2726

@@ -41,8 +40,8 @@ export class TypeHintProvider {
4140
* @param param The parameter name.
4241
* @returns An array of type hints, ordered by estimation accuracy.
4342
*/
44-
public async getTypeHints(param: string): Promise<TypeHint[]> {
45-
const typeHints: TypeHint[] = [];
43+
public async getTypeHints(param: string): Promise<string[]> {
44+
const typeHints: string[] = [];
4645
const documentText = this.doc.getText();
4746

4847
const typingHintProvider = new TypingHintProvider(documentText, this.typeContainer);
@@ -114,7 +113,7 @@ export class TypeHintProvider {
114113
return null;
115114
}
116115

117-
private typeGuessFor(param: string, typeHints: TypeHint[]): string | null {
116+
private typeGuessFor(param: string, typeHints: string[]): string | null {
118117
const typeGuesses: { [key: string]: string } = {
119118
"string": PythonType.String,
120119
"text": PythonType.String,
@@ -132,18 +131,37 @@ export class TypeHintProvider {
132131
}
133132
return null;
134133
}
134+
135+
136+
private add(typeName: string, typeHints: string[]) {
137+
typeName = typeName.trim();
138+
if (this.typeNotIncluded(typeName)) {
139+
typeHints.push(typeName);
140+
this.typeNamesIncludedInResult.push(typeName);
141+
}
142+
}
143+
144+
private typeNotIncluded(type: string): boolean {
145+
return !this.typeNamesIncludedInResult.includes(type);
146+
}
147+
148+
private tryAdd(type: string | null, typeHints: string[]) {
149+
if (type) {
150+
this.add(type, typeHints);
151+
}
152+
}
135153

136154
private tryAddTypingHints(
137155
typingFound: boolean,
138156
searchResult: VariableSearchResult | null,
139157
typingHintProvider: TypingHintProvider,
140-
typeHints: TypeHint[]
158+
typeHints: string[]
141159
) {
142160
if (typingFound) {
143-
const hints: TypeHint[] | null = typingHintProvider.getTypingHints(searchResult);
161+
const hints: string[] | null = typingHintProvider.getTypingHints(searchResult);
144162
if (hints) {
145163
for (const hint of hints) {
146-
this.addTypeHint(hint, typeHints);
164+
this.add(hint, typeHints);
147165
}
148166
}
149167
}
@@ -153,37 +171,13 @@ export class TypeHintProvider {
153171
typingFound: boolean,
154172
typeName: string,
155173
typingHintProvider: TypingHintProvider,
156-
typeHints: TypeHint[]
174+
typeHints: string[]
157175
) {
158176
if (typingFound) {
159177
const typingHint = typingHintProvider.getTypingHint(typeName);
160178
if (typingHint) {
161-
this.addTypeHint(typingHint, typeHints);
179+
this.add(typingHint, typeHints);
162180
}
163181
}
164182
}
165-
166-
private typeNotIncluded(type: string): boolean {
167-
return !(type in this.typesIncludedInResult);
168-
}
169-
170-
private add(type: string, typeHints: TypeHint[]) {
171-
if (this.typeNotIncluded(type)) {
172-
typeHints.push({ label: labelFor(type) });
173-
this.typesIncludedInResult[type] = type;
174-
}
175-
}
176-
177-
private addTypeHint(hint: TypeHint, typeHints: TypeHint[]) {
178-
if (this.typeNotIncluded(hint.label)) {
179-
typeHints.push(hint);
180-
this.typesIncludedInResult[hint.label] = hint.label;
181-
}
182-
}
183-
184-
private tryAdd(type: string | null, typeHints: TypeHint[]) {
185-
if (type) {
186-
this.add(type, typeHints);
187-
}
188-
}
189183
}

src/typeSearch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ export class TypeSearch {
138138
}
139139
}
140140
searches.pop();
141-
for (const e of searches) {
142-
const typeName = e[0];
143-
if (new RegExp(e[2]).test(value)) {
141+
for (const s of searches) {
142+
const typeName = s[0];
143+
if (new RegExp(s[2]).test(value)) {
144144
return typeName;
145145
}
146146
}

0 commit comments

Comments
 (0)