Skip to content
Open
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
3 changes: 3 additions & 0 deletions packages/pyright-internal/src/analyzer/typePrinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,9 @@ function printTypeWithCythonDetails(type: Type, objName: string) {
if (details.isPublic) {
prefixes.push('public');
}
if (details.isApi) {
prefixes.push('api');
}
if (details.isConst) {
prefixes.push('const');
}
Expand Down
2 changes: 2 additions & 0 deletions packages/pyright-internal/src/analyzer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export namespace TypeBase {
isConst: node ? CTypeNode.isConstant(node) : false,
isVolatile: node ? CTypeNode.isVolatile(node) : false,
isPublic: node ? CTypeNode.isPublic(node) : false,
isApi: node ? CTypeNode.isApi(node) : false,
isReadOnly: node ? CTypeNode.isReadOnly(node) : false,
numMods: node ? CTypeNode.numModifiers(node) : [],
trailType: node ? CTypeNode.trailType(node) : CTrailType.None,
Expand Down Expand Up @@ -606,6 +607,7 @@ export interface CythonDetails {
isVolatile?: boolean;
isReadOnly?: boolean;
isPublic?: boolean;
isApi?: boolean;
numMods?: string[]; // Numeric modifiers
trailType?: CTrailType;

Expand Down
15 changes: 15 additions & 0 deletions packages/pyright-internal/src/common/configOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,17 @@ export function getOffDiagnosticRuleSet(): DiagnosticRuleSet {
return diagSettings;
}

/** Cython: minimal diagnostics — only syntax/parse errors. Suppresses import and undefined-variable noise for .pyx/.pxd. */
export function getCythonDiagnosticRuleSet(): DiagnosticRuleSet {
const diagSettings: DiagnosticRuleSet = {
...getOffDiagnosticRuleSet(),
reportMissingImports: 'none',
reportMissingModuleSource: 'none',
reportUndefinedVariable: 'none',
};
return diagSettings;
}

export function getBasicDiagnosticRuleSet(): DiagnosticRuleSet {
const diagSettings: DiagnosticRuleSet = {
printUnknownAsAny: false,
Expand Down Expand Up @@ -818,6 +829,10 @@ export class ConfigOptions {
return getOffDiagnosticRuleSet();
}

if (typeCheckingMode === 'cython') {
return getCythonDiagnosticRuleSet();
}

return getBasicDiagnosticRuleSet();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ namespace Keywords {
'const',
'readonly',
'public',
'api',
'signed',
'unsigned',
'long',
Expand Down
4 changes: 4 additions & 0 deletions packages/pyright-internal/src/parser/parseNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2572,6 +2572,10 @@ export namespace CTypeNode {
return hasModifier(node, KeywordType.Public);
}

export function isApi(node: CTypeNode) {
return hasModifier(node, KeywordType.Api);
}

export function isReadOnly(node: CTypeNode) {
return hasModifier(node, KeywordType.Readonly);
}
Expand Down
1 change: 1 addition & 0 deletions packages/pyright-internal/src/parser/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const _keywords: Map<string, KeywordType> = new Map([
['const', KeywordType.Const],
['readonly', KeywordType.Readonly],
['public', KeywordType.Public],
['api', KeywordType.Api],
['signed', KeywordType.Signed],
['unsigned', KeywordType.Unsigned],
['long', KeywordType.Long],
Expand Down
3 changes: 3 additions & 0 deletions packages/pyright-internal/src/parser/tokenizerTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export const enum KeywordType {
Const,
Readonly,
Public,
Api,
Signed,
Unsigned,
Long,
Expand Down Expand Up @@ -196,6 +197,7 @@ export const varModifiers = [
KeywordType.Readonly,
KeywordType.Inline,
KeywordType.Public,
KeywordType.Api,
KeywordType.Volatile,
];

Expand All @@ -218,6 +220,7 @@ export const softKeywords = [
KeywordType.Const,
KeywordType.Readonly,
KeywordType.Public,
KeywordType.Api,
KeywordType.Signed,
KeywordType.Unsigned,
KeywordType.Long,
Expand Down
7 changes: 7 additions & 0 deletions packages/pyright-internal/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,14 @@ export class PyrightServer extends LanguageServerBase {
});
serverSettings.includePaths = cythonPaths;
}
if (cythonSection.typeCheckingMode !== undefined && isString(cythonSection.typeCheckingMode)) {
serverSettings.typeCheckingMode = cythonSection.typeCheckingMode;
}
}

// ! Cython: use minimal diagnostics for .pyx/.pxd to avoid false positives
// (missing imports, undefined vars from cimports/C types). Set cython.typeCheckingMode to override.
serverSettings.typeCheckingMode = serverSettings.typeCheckingMode ?? 'cython';
} catch (error) {
this.console.error(`Error reading settings: ${error}`);
}
Expand Down