Skip to content

Commit

Permalink
fix incorrect semantic highlighting of Never
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Sep 4, 2024
1 parent 09ec86c commit dd8d055
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ParseTreeWalker } from './parseTreeWalker';
import { TypeEvaluator } from './typeEvaluatorTypes';
import { ClassType, FunctionType, OverloadedType, Type, TypeCategory, TypeFlags } from './types';
import { ClassType, FunctionType, getTypeAliasInfo, OverloadedType, Type, TypeCategory, TypeFlags } from './types';
import {
ClassNode,
DecoratorNode,
Expand Down Expand Up @@ -218,10 +218,8 @@ export class SemanticTokensWalker extends ParseTreeWalker {
// to differentiate between "instances" of `Never` and type aliases/annotations of Never.
// this is probably extremely cringe since i have no idea what this is doing and i literally
// just brute forced random shit until all the tests passed
(typeResult.type.category !== TypeCategory.Never &&
typeResult.type.category !== TypeCategory.Unbound &&
typeResult.type.flags & TypeFlags.Instantiable) ||
(typeResult.type.category === TypeCategory.Unbound && !typeResult.includesIllegalTypeAliasDecl)
(typeResult.type.category === TypeCategory.Never && !typeResult.includesVariableDecl) ||
(getTypeAliasInfo(type) && !typeResult.includesIllegalTypeAliasDecl)
) {
this._addItem(node.start, node.length, SemanticTokenTypes.type, []);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ if (process.platform !== 'win32' || !process.env['CI']) {
expect(result).toStrictEqual([
//TODO: fix duplicates
{ type: 'namespace', modifiers: [], start: 5, length: 6 },
{ type: 'class', modifiers: [], start: 19, length: 5 },
{ type: 'class', modifiers: [], start: 19, length: 5 },
{ type: 'type', modifiers: [], start: 19, length: 5 },
{ type: 'type', modifiers: [], start: 19, length: 5 },
{ type: 'class', modifiers: [], start: 26, length: 8 },
{ type: 'class', modifiers: [], start: 38, length: 3 },
{ type: 'namespace', modifiers: [], start: 47, length: 11 },
Expand Down Expand Up @@ -52,12 +52,12 @@ if (process.platform !== 'win32' || !process.env['CI']) {
const result = semanticTokenizeSampleFile('never.py');
expect(result).toStrictEqual([
{ type: 'namespace', modifiers: [], start: 5, length: 6 }, // typing
{ type: 'class', modifiers: [], start: 19, length: 5 }, // Never
{ type: 'class', modifiers: [], start: 19, length: 5 }, // Never
{ type: 'type', modifiers: [], start: 19, length: 5 }, // Never
{ type: 'type', modifiers: [], start: 19, length: 5 }, // Never
{ type: 'variable', modifiers: [], start: 26, length: 3 }, // foo
{ type: 'type', modifiers: [], start: 31, length: 5 }, // Never
{ type: 'class', modifiers: [], start: 37, length: 3 }, // bar
{ type: 'class', modifiers: [], start: 43, length: 5 }, // Never
{ type: 'type', modifiers: [], start: 37, length: 3 }, // bar
{ type: 'type', modifiers: [], start: 43, length: 5 }, // Never
{ type: 'function', modifiers: ['definition'], start: 54, length: 3 }, // baz
{ type: 'function', modifiers: [], start: 54, length: 3 }, // baz
{ type: 'type', modifiers: [], start: 63, length: 5 }, // Never
Expand All @@ -69,10 +69,10 @@ if (process.platform !== 'win32' || !process.env['CI']) {
{ type: 'type', modifiers: [], start: 112, length: 5 }, // Never
{ type: 'parameter', modifiers: [], start: 120, length: 3 }, // foo
{ type: 'variable', modifiers: [], start: 128, length: 5 }, // value
{ type: 'class', modifiers: [], start: 135, length: 4 }, // Type
{ type: 'class', modifiers: [], start: 142, length: 5 }, // Never
{ type: 'type', modifiers: [], start: 135, length: 4 }, // Type
{ type: 'type', modifiers: [], start: 142, length: 5 }, // Never
{ type: 'variable', modifiers: [], start: 148, length: 5 }, // value
{ type: 'variable', modifiers: [], start: 155, length: 4 }, // Type (should be type. https://github.com/DetachHead/basedpyright/issues/490)
{ type: 'type', modifiers: [], start: 155, length: 4 }, // Type
{ type: 'function', modifiers: ['definition'], start: 169, length: 8 }, // inferred
{ type: 'function', modifiers: [], start: 169, length: 8 }, // inferred
{ type: 'variable', modifiers: [], start: 185, length: 5 }, // value
Expand Down

0 comments on commit dd8d055

Please sign in to comment.