Skip to content

Commit

Permalink
Merge pull request #12 from rikukissa/1.5.1
Browse files Browse the repository at this point in the history
Implement following types to different modules
  • Loading branch information
rikukissa committed May 19, 2021
2 parents 39a186f + 6d036fe commit c6b6d04
Show file tree
Hide file tree
Showing 18 changed files with 578 additions and 159 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ From 1.4.0 forward also Promises are supported. All other values (functions etc.

## Release Notes

## [Unreleased]
## [1.5.1] - 2021-05-18

### Fixed

- Multiple typeholes can now exist with the same id. Each update from all of them updates all types attached to the holes. Useful, for example, when you want to have multiple typeholes update the same type.
- No duplicated interfaces anymore when the generated top-level type is a `ParenthesizedType`
- Interface not updating when it was in a different file than the typehole
- Types not updating when some other file was focused in the editor
- `typehole.tNaN` [issue](https://github.com/rikukissa/typehole/issues/7) when there have been typeholes with a non `t<number>` format

## [1.5.0] - 2021-05-15
Expand Down
189 changes: 185 additions & 4 deletions packages/extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publisher": "rikurouvila",
"description": "🧪 Take samples of runtime values and turn them into type definitions automatically",
"repository": "https://github.com/rikukissa/typehole",
"version": "1.5.0",
"version": "1.5.1",
"private": true,
"icon": "images/logo.png",
"galleryBanner": {
Expand Down
1 change: 0 additions & 1 deletion packages/extension/src/code-action.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as vscode from "vscode";
import * as ts from "typescript";
import { isValidSelection } from "./parse/expression";
import { getAST } from "./parse/module";
import {
Expand Down
28 changes: 20 additions & 8 deletions packages/extension/src/commands/addATypehole.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import * as ts from 'typescript';
import * as vscode from 'vscode';
import * as ts from "typescript";
import * as vscode from "vscode";

import { getEditorRange } from '../editor/utils';
import { getEditorRange } from "../editor/utils";
import {
getPlaceholderTypeName,
insertRecorderToSelection,
insertTypeholeImport,
last,
startRenamingPlaceholderType,
} from '../extension';
import { findTypeholes, getAST, getNodeEndPosition, getNodeStartPosition, getParentOnRootLevel } from '../parse/module';
import { getNextAvailableId } from '../state';
import { getWrappingVariableDeclaration, insertGenericTypeParameter, insertTypeReference } from '../transforms/insertTypes';
} from "../extension";
import {
findTypeholes,
getAST,
getNodeEndPosition,
getNodeStartPosition,
getParentOnRootLevel,
} from "../parse/module";
import { getNextAvailableId } from "../state";
import {
getWrappingVariableDeclaration,
insertGenericTypeParameter,
insertTypeReference,
} from "../transforms/insertTypes";

export async function addATypehole() {
const editor = vscode.window.activeTextEditor;
Expand All @@ -22,10 +32,12 @@ export async function addATypehole() {

const fullFile = document.getText();
const ast = getAST(fullFile);

const id = getNextAvailableId();

await editor.edit((editBuilder) => {
insertTypeholeImport(ast, editBuilder);

insertRecorderToSelection(id, editor, editBuilder);
});

Expand All @@ -39,6 +51,7 @@ export async function addATypehole() {
getWrappingVariableDeclaration(newlyCreatedTypeHole);

const typeName = getPlaceholderTypeName(updatedAST);

await editor.edit((editBuilder) => {
if (variableDeclaration && !variableDeclaration.type) {
insertTypeToVariableDeclaration(
Expand Down Expand Up @@ -121,4 +134,3 @@ function insertTypeToVariableDeclaration(
);
}
}

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as vscode from "vscode";
import { unique } from "../parse/utils";
import { getState } from "../state";
import { getAllHoles } from "../state";
import { removeTypeholesFromFile } from "./removeTypeholesFromCurrentFile";

export async function removeTypeholesFromAllFiles() {
const holes = getState().holes;
const files = holes.map((h) => h.fileName).filter(unique);
const holes = getAllHoles();
const files = holes.flatMap((h) => h.fileNames).filter(unique);

for (const file of files) {
let document: null | vscode.TextDocument = null;
Expand Down
Loading

0 comments on commit c6b6d04

Please sign in to comment.