Skip to content
This repository has been archived by the owner on Jan 30, 2022. It is now read-only.

Commit

Permalink
fix: improve fluent static constant goToDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
0x706b committed Jan 25, 2022
1 parent 3430f69 commit 7db766d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
12 changes: 6 additions & 6 deletions effect/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import { Effect } from "./prelude.js";
import { Maybe } from "./prelude.js";

export const isPositive = (n: number) =>
n > 0 ? Maybe.just("positive") : Maybe.nothing()
n > 0 ? Maybe.just("positive") : Maybe.nothing();

export const isPositiveEff = (n: number) =>
n > 0 ? Effect("positive") : Effect.fail("negative")
n > 0 ? Effect("positive") : Effect.fail("negative");

export const resultEither = isPositive(0).match(() => "nope", () => "yeah")
export const resultEither = isPositive(0).match(() => "nope", () => "yeah");

export const prog = Effect.do
.bind("a", () => Effect(0))
.bind("b", () => Effect(1))
.bind("c", () => Effect(2))
.bind("d", () => Effect(4) + Effect(5))
.map(({ a, b, c, d: { tuple: [e, f] } }) => `result: ${a + b + c} ${e} ${f}`)
.flatMap((s) => Effect(console.log(s)))
.flatMap((s) => Effect(console.log(s)));

export const result = prog | Effect.fail("error")
export const result = prog | Effect.fail("error");

prog.unsafeRunPromise()

export const xxx = pipe(0, n => n + 1, n => `hello: ${n}`)
export const xxx = pipe(0, n => n + 1, n => `hello: ${n}`)
24 changes: 20 additions & 4 deletions src/services/goToDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,28 @@ namespace ts.GoToDefinition {
const staticSymbol = typeChecker.getStaticExtension(type, name);
if(staticSymbol && !isCallExpression(parent.parent)) {
const declaration = staticSymbol.patched.valueDeclaration!;
let start: number;
let length: number;
if(declaration.original && isNamedDeclaration(declaration.original)) {
start = declaration.original.name.getStart();
length = declaration.original.getWidth();
}
else if(isNamedDeclaration(declaration)) {
start = declaration.name.getStart();
length = declaration.getWidth();
}
else {
start = declaration.getStart();
length = declaration.getWidth();
}

if(start === -1 || length === -1) {
return undefined;
}

return [{
fileName: staticSymbol.definition.fileName,
textSpan: {
start: declaration.pos + 1,
length: declaration.end - declaration.pos
},
textSpan: { start, length },
kind: SymbolDisplay.getSymbolKind(typeChecker, staticSymbol.patched, node),
name: typeChecker.symbolToString(staticSymbol.patched),
containerKind: undefined!,
Expand Down

0 comments on commit 7db766d

Please sign in to comment.