mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
eslint/prettier fixes, platform and version detection (#749)
This commit is contained in:
parent
93e1fc7314
commit
600cd7ab43
65
.github/workflows/codeql.yml
vendored
65
.github/workflows/codeql.yml
vendored
@ -1,4 +1,4 @@
|
||||
name: "Code scanning - action"
|
||||
name: 'Code scanning - action'
|
||||
|
||||
on:
|
||||
push:
|
||||
@ -8,45 +8,44 @@ on:
|
||||
|
||||
jobs:
|
||||
CodeQL-Build:
|
||||
|
||||
# CodeQL runs on ubuntu-latest and windows-latest
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
# We must fetch at least the immediate parents so that if this is
|
||||
# a pull request then we can checkout the head.
|
||||
fetch-depth: 2
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
# We must fetch at least the immediate parents so that if this is
|
||||
# a pull request then we can checkout the head.
|
||||
fetch-depth: 2
|
||||
|
||||
# If this run was triggered by a pull request event, then checkout
|
||||
# the head of the pull request instead of the merge commit.
|
||||
- run: git checkout HEAD^2
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
# Override language selection by uncommenting this and choosing your languages
|
||||
# with:
|
||||
# languages: go, javascript, csharp, python, cpp, java
|
||||
# If this run was triggered by a pull request event, then checkout
|
||||
# the head of the pull request instead of the merge commit.
|
||||
- run: git checkout HEAD^2
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
# Override language selection by uncommenting this and choosing your languages
|
||||
# with:
|
||||
# languages: go, javascript, csharp, python, cpp, java
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
|
@ -11,18 +11,18 @@
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { commands, extensions, ExtensionContext, Position, Range, TextEditor, TextEditorEdit, Uri } from 'vscode';
|
||||
import { commands, ExtensionContext, extensions, Position, Range, TextEditor, TextEditorEdit, Uri } from 'vscode';
|
||||
import {
|
||||
CancellationToken,
|
||||
ConfigurationParams,
|
||||
ConfigurationRequest,
|
||||
HandlerResult,
|
||||
LanguageClient,
|
||||
LanguageClientOptions,
|
||||
ResponseError,
|
||||
ServerOptions,
|
||||
TextEdit,
|
||||
TransportKind,
|
||||
ConfigurationParams,
|
||||
CancellationToken,
|
||||
ConfigurationRequest,
|
||||
HandlerResult,
|
||||
ResponseError,
|
||||
} from 'vscode-languageclient/node';
|
||||
|
||||
import { Commands } from '../../server/src/commands/commands';
|
||||
|
@ -145,6 +145,13 @@ export class AnalyzerService {
|
||||
this._commandLineOptions = commandLineOptions;
|
||||
|
||||
const configOptions = this._getConfigOptions(commandLineOptions);
|
||||
|
||||
if (configOptions.pythonPath) {
|
||||
// make sure we have default python environment set
|
||||
configOptions.ensureDefaultPythonVersion(configOptions.pythonPath, this._console);
|
||||
configOptions.ensureDefaultPythonPlatform(this._console);
|
||||
}
|
||||
|
||||
this._backgroundAnalysisProgram.setConfigOptions(configOptions);
|
||||
|
||||
this._executionRootPath = normalizePath(
|
||||
|
@ -36,6 +36,7 @@ import { HoverProvider, HoverResults } from '../languageService/hoverProvider';
|
||||
import { performQuickAction } from '../languageService/quickActions';
|
||||
import { ReferencesProvider, ReferencesResult } from '../languageService/referencesProvider';
|
||||
import { SignatureHelpProvider, SignatureHelpResults } from '../languageService/signatureHelpProvider';
|
||||
import { Localizer } from '../localization/localize';
|
||||
import { ModuleNode } from '../parser/parseNodes';
|
||||
import { ModuleImport, ParseOptions, Parser, ParseResults } from '../parser/parser';
|
||||
import { Token } from '../parser/tokenizerTypes';
|
||||
@ -53,7 +54,6 @@ import { SourceMapper } from './sourceMapper';
|
||||
import { SymbolTable } from './symbol';
|
||||
import { TestWalker } from './testWalker';
|
||||
import { TypeEvaluator } from './typeEvaluator';
|
||||
import { Localizer } from '../localization/localize';
|
||||
|
||||
const _maxImportCyclesPerFile = 4;
|
||||
|
||||
|
@ -984,14 +984,7 @@ export class ConfigOptions {
|
||||
}
|
||||
}
|
||||
|
||||
// If no default python version was specified, retrieve the version
|
||||
// from the currently-selected python interpreter.
|
||||
if (this.defaultPythonVersion === undefined) {
|
||||
this.defaultPythonVersion = this._getPythonVersionFromPythonInterpreter(pythonPath, console);
|
||||
if (this.defaultPythonVersion !== undefined) {
|
||||
console.info(`Assuming Python version ${versionToString(this.defaultPythonVersion)}`);
|
||||
}
|
||||
}
|
||||
this.ensureDefaultPythonVersion(pythonPath, console);
|
||||
|
||||
// Read the default "pythonPlatform".
|
||||
this.defaultPythonPlatform = undefined;
|
||||
@ -1003,21 +996,7 @@ export class ConfigOptions {
|
||||
}
|
||||
}
|
||||
|
||||
// If no default python platform was specified, assume that the
|
||||
// user wants to use the current platform.
|
||||
if (this.defaultPythonPlatform === undefined) {
|
||||
if (process.platform === 'darwin') {
|
||||
this.defaultPythonPlatform = 'Darwin';
|
||||
} else if (process.platform === 'linux') {
|
||||
this.defaultPythonPlatform = 'Linux';
|
||||
} else if (process.platform === 'win32') {
|
||||
this.defaultPythonPlatform = 'Windows';
|
||||
}
|
||||
|
||||
if (this.defaultPythonPlatform !== undefined) {
|
||||
console.info(`Assuming Python platform ${this.defaultPythonPlatform}`);
|
||||
}
|
||||
}
|
||||
this.ensureDefaultPythonPlatform(console);
|
||||
|
||||
// Read the "typeshedPath" setting.
|
||||
this.typeshedPath = undefined;
|
||||
@ -1090,6 +1069,39 @@ export class ConfigOptions {
|
||||
}
|
||||
}
|
||||
|
||||
ensureDefaultPythonPlatform(console: ConsoleInterface) {
|
||||
// If no default python platform was specified, assume that the
|
||||
// user wants to use the current platform.
|
||||
if (this.defaultPythonPlatform !== undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
this.defaultPythonPlatform = 'Darwin';
|
||||
} else if (process.platform === 'linux') {
|
||||
this.defaultPythonPlatform = 'Linux';
|
||||
} else if (process.platform === 'win32') {
|
||||
this.defaultPythonPlatform = 'Windows';
|
||||
}
|
||||
|
||||
if (this.defaultPythonPlatform !== undefined) {
|
||||
console.info(`Assuming Python platform ${this.defaultPythonPlatform}`);
|
||||
}
|
||||
}
|
||||
|
||||
ensureDefaultPythonVersion(pythonPath: string | undefined, console: ConsoleInterface) {
|
||||
// If no default python version was specified, retrieve the version
|
||||
// from the currently-selected python interpreter.
|
||||
if (this.defaultPythonVersion !== undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.defaultPythonVersion = this._getPythonVersionFromPythonInterpreter(pythonPath, console);
|
||||
if (this.defaultPythonVersion !== undefined) {
|
||||
console.info(`Assuming Python version ${versionToString(this.defaultPythonVersion)}`);
|
||||
}
|
||||
}
|
||||
|
||||
applyDiagnosticOverrides(diagnosticSeverityOverrides: DiagnosticSeverityOverridesMap | undefined) {
|
||||
if (!diagnosticSeverityOverrides) {
|
||||
return;
|
||||
|
@ -261,6 +261,7 @@ function printUsage() {
|
||||
}
|
||||
|
||||
function getVersionString() {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const version = require('package.json').version;
|
||||
return version.toString();
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ class PyrightServer extends LanguageServerBase {
|
||||
private _controller: CommandController;
|
||||
|
||||
constructor() {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const version = require('../package.json').version || '';
|
||||
super({
|
||||
productName: 'Pyright',
|
||||
|
@ -21,7 +21,6 @@ import { compareStringsCaseInsensitive, compareStringsCaseSensitive } from '../.
|
||||
|
||||
export const HOST: TestHost = createHost();
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
|
||||
export interface TestHost {
|
||||
useCaseSensitiveFileNames(): boolean;
|
||||
getAccessibleFileSystemEntries(dirname: string): FileSystemEntries;
|
||||
|
Loading…
Reference in New Issue
Block a user